php Wordpress 通过 id 获取多个帖子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8423934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wordpress get multiple posts by id
提问by RIK
I need to get multiple posts in wordpress by ID.
我需要通过 ID 在 wordpress 中获取多个帖子。
get_posts('p=34,36');
I assumed that that might work, but it only gives the first post.
我认为这可能有效,但它只给出了第一篇文章。
I tried then to use an array:
然后我尝试使用一个数组:
$args = array( 'p' => array(34,36));
That delivered no results.
那没有结果。
get_posts('p=34+36');
NO and get_posts('p=34&p=36');
Last one only
get_posts('p=34+36');
没有和get_posts('p=34&p=36');
只有最后一个
Any ideas?
有任何想法吗?
回答by postpostmodern
$args = array( 'post__in' => array(34,36) );
Be sure to check out http://codex.wordpress.org/Class_Reference/WP_Queryas well, the section Interacting with WP_Querywill be very valuable to you.
请务必查看http://codex.wordpress.org/Class_Reference/WP_Query,与 WP_Query 交互部分对您非常有价值。
回答by kdgilang
$args = array(
'post_type' => 'page', // must
'post__in' => array(34,36)
);
$posts = get_posts($args);
print_r($posts);
this may help you.
这可能对你有帮助。