Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a wp_query $wp_query = new WP_Query($args); but for some reason the $wp_query->post_count only shows the amount of posts on each page. So if I set 'showposts' => '10' and 12 results are found, page one will say '10 results found' and page 2 shows '2 results found'. Why is this? I can't figure it out.

$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
share|improve this question
2  
Have you looked at the variable $wp_query->found_posts as well? –  toscho Dec 4 '12 at 13:52
add comment

1 Answer 1

up vote 5 down vote accepted

$wp_query->post_count is supposed to work exactly like that. To get the total number of posts that exist in the database, use $wp_query->found_posts

share|improve this answer
    
..and as simple as that, it works. Thanks so much guys! –  Graeme Dec 4 '12 at 14:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.