简体   繁体   English

get_posts的include选项有效,但不限制帖子数

[英]include option for get_posts works but is not limiting the number of posts

I am using the include option for get_posts and the numberposts is not limiting the amount of posts I have set right now which is 1, it simply loads all include ids that are set. 我正在为get_posts使用include选项,并且numberposts并不限制我现在设置的帖子数量,即1,它只是加载设置的所有include id。 Is it not possible to limit the number of include posts ids? 不能限制包含帖子ID的数量吗? Here is my code. 这是我的代码。

$image_list = get_posts(array(
            'numberposts' =>  1,
            'include'   => '559,117,129',
            'post_type' => 'ft_gallery',
 ));

Use 'numberposts'=> 2 as described in the documentation: https://developer.wordpress.org/reference/functions/get_posts/ . 如文档中所述使用'numberposts'=> 2: https : //developer.wordpress.org/reference/functions/get_posts/ It's an 'alias' for posts_per_page. 这是posts_per_page的“别名”。 Tested in shortcode on my localhost and it works 在我的本地主机上以简码测试,它可以正常工作

https://codex.wordpress.org/Template_Tags/get_posts https://codex.wordpress.org/Template_Tags/get_posts

Note: The posts_per_page parameter does NOT work without setting the offset parameter. 注意:如果不设置offset参数,posts_per_page参数将不起作用。

So the solution is using post__in and making sure the list of numbers is in an array format. 因此,解决方案是使用post__in并确保数字列表采用数组格式。 Thanks for everything efforts. 感谢您所做的一切。

$image_list = get_posts(array(
        'numberposts' =>  1,
        'post__in'   => array([0] => 559 [1] => 117 [2] => 129 [3] => 496 [4] => 797),
        'post_type' => 'ft_gallery',
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM