admin管理员组文章数量:1122846
How do I use get_posts to filter against a single post id? (I don't want to use get_post because am using this in another function that could take other parameters and should return an array). The following methods are not working:
get_posts(array(
'ID' => 12345,
));
get_posts(array(
'p' => 12345,
));
get_posts(array(
'post' => 12345,
));
get_posts(array(
'post__in' => array(12345),
));
How do I use get_posts to filter against a single post id? (I don't want to use get_post because am using this in another function that could take other parameters and should return an array). The following methods are not working:
get_posts(array(
'ID' => 12345,
));
get_posts(array(
'p' => 12345,
));
get_posts(array(
'post' => 12345,
));
get_posts(array(
'post__in' => array(12345),
));
Share
Improve this question
edited Dec 10, 2021 at 18:17
tklodd
asked Dec 10, 2021 at 17:38
tkloddtklodd
1296 bronze badges
1 Answer
Reset to default 1Nevermind, all of these methods work if I add the post_type parameter to the query:
get_posts(array(
'ID' => 12345,
'post_type' => array('any'),
));
get_posts(array(
'p' => 12345,
'post_type' => array('any'),
));
get_posts(array(
'post' => 12345,
'post_type' => array('any'),
));
get_posts(array(
'post__in' => array(12345),
'post_type' => array('any'),
));
This is a really stupid design decision; any post type should be assumed if the parameter is omitted.
本文标签: How to use getposts to filter against a single post id
版权声明:本文标题:How to use get_posts to filter against a single post id? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283164a1926876.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论