如何使用 get_posts 获取大于 X (ID) 的帖子 [英] How to get Posts Greater Than X (ID) using get_posts

查看:23
本文介绍了如何使用 get_posts 获取大于 X (ID) 的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$args = array('numberposts' => 10, 'tag' => 'my-tag', 'ID' => 555');
$posts = get_posts($args);

我只想从特定标签中提取 10 条记录,并且 ID 小于一个数字.有没有办法用 get_posts 参数做到这一点?如何在参数数组中指定大于、小于或不喜欢?

I want to bring only 10 records from an specific tag and that the ID is less than a number. Is there any way to do this with the get_posts arguments? How can I specify Greater Than, Less Than or Not Like in the arguments array?

谢谢...

推荐答案

如果您想获取 ID 小于 X 的帖子,这是一个不错的解决方案:

A nice solution if you want to get the posts with an ID lower than X:

$post_ids = range(1, 555); 

$args = array('numberposts' => 10, 
'tag' => 'my-tag', 
'post__in' => $post_ids');

$posts = get_posts($args);

girlieworks 的道具在这里:https://wordpress.org/support/topic/wp_query-how-to-get-posts-with-and-id-lower-than?reply=7#post-8203891

props to girlieworks here: https://wordpress.org/support/topic/wp_query-how-to-get-posts-with-and-id-lower-than?replies=7#post-8203891

这篇关于如何使用 get_posts 获取大于 X (ID) 的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆