I have loop and I want to get the amount of posts on a current page. So I try:

<?php $post_number = $wp_query->post_count; ?>
<?php echo($post_number) ; ?>
<?php while ( have_posts() ) : the_post();?>
    <?php get_template_part( 'post', get_post_format() );?>
<?php endwhile; ?>

but it doesn't work. I can't see result. So how can I get amount of posts?

  • Can you please specify what do you mean by not working? Are you getting error? Wrong number? No result at all?
    – Johansson
    Commented Apr 19, 2017 at 21:01

2 Answers 2


You can use the below to output the post amounts

$args = array(
  'post_type' => 'post', 
  'showposts' => '10'
 $wp_query = new WP_Query($args);
 // amount of posts per on the page
 $post_number = $wp_query->post_count;
 // amount of posts across the post pages
 $post_number2 = $wp_query->found_posts;
 echo $post_number.'<br />';
 echo $post_number2.'<br />';
 while ( have_posts() ) : the_post();
 php get_template_part( 'post', get_post_format() );
 php endwhile; 

You could try this $count = $GLOBALS['wp_query']->found_posts This will show total found post on that page global query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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