Post_count仅显示每页结果数


17

我有一个wp_query,$wp_query = new WP_Query($args);但由于某种原因,它$wp_query->post_count仅显示每个页面上的帖子数量。因此,如果我设置'showposts' => '10'并找到12个结果,则第一页将显示“找到10个结果”,而第二页显示“找到了2个结果”。为什么是这样?我不知道。

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'post_type' => 'post', 
  'showposts' => '10',
  'paged' => $paged
);
$wp_query = new WP_Query($args);
echo "Search found ".$wp_query->post_count."results";
if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
// the loop

2
您是否也查看过变量$wp_query->found_posts
fuxia

Answers:


33

$wp_query->post_count应该完全像那样工作。要获取数据库中存在的帖子总数,请使用$wp_query->found_posts


1
..就这么简单,它就可以了。非常感谢你们!
zilj 2012年

我对此有疑问。当我使用found_posts过滤结果时-数字会更改。我想保持静态的总结果数不变。我该怎么办?
Joanna Mikalai '17
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.