WordPress分页返回1篇文章,而它应该返回10篇


WordPress pagination returns 1 post when it should return 10

我的第一个页面上有4个查询。每个部分都很完美,除了作品集部分。我想在我的作品集部分显示10个帖子,但我的查询只显示一个帖子。

$args = array(
    'post_type' => 'project-portfolio',
    'numberposts' => 10
    );
    $the_query = new WP_Query ($args);
if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
wp_title();
endwhile; 
else:
endif; 
wp_reset_query(); 

我不相信numberpostsWP_Query的有效参数(因为它在WP_Query的法典页面中没有提到),但我相信posts_per_page是您正在寻找的。

根据Wordpress Codex WP_Query Page

posts_per_page (int) -每个页面显示的帖子数(2.1版可用,取代了showposts参数)。使用'posts_per_page'=>-1显示所有帖子('offset'参数被忽略,值为-1)。如果使用此参数后分页关闭,请设置'分页'参数。注意:如果查询是在一个提要中,wordpress会用存储的'posts_per_rss'选项覆盖这个参数。要重新设置限制,请尝试使用'post_limits'过滤器或'pre_option_posts_per_rss'过滤器并返回-1

所以你的$args数组应该是
$args = array(
    'post_type' => 'project-portfolio',
    'posts_per_page' => 10
    );

编辑

参数numberposts可在get_posts的法典中找到,其中规定

注意:'numberposts'和'posts_per_page'可以互换使用。

在接下来的句子中,它表示

完整参数列表见WP_Query。

但是,WP_Query的抄本中没有numberposts参数。

编辑

https://stackoverflow.com/a/3335128/2687861声明numberposts已折旧