首页 > 解决方案 > get_posts 的包含选项有效,但不限制帖子数量

问题描述

我正在使用 get_posts 的 include 选项,并且 numberposts 并不限制我现在设置的帖子数量,即 1,它只是加载所有设置的包含 ID。不能限制包含帖子ID的数量吗?这是我的代码。

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

标签: phpwordpresspagination

解决方案


所以解决方案是使用 post__in 并确保数字列表是数组格式。感谢一切努力。

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

推荐阅读