0

Just a quick one but I am stuck in doing this. I am running a WP_Query for a category and and want to know how to display the number of posts in a category using WP Query!

This is the start of my WP_query but how to I just simply echo out the number of posts in this category?! It is driving me mad!

<?php

$args = array(
    'cat' => 33,
    'posts_per_page' => 500,
);

$the_query = new WP_Query( $args );
?>


<?php if ( $the_query->have_posts() ) :?> 


    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

Thanks!

2

You can use the found_posts property, which is the total number posts for the current query:

echo $the_query->found_posts;
  • Perfect thanks for that, I will mark as the answer - have a great day :) – user3502952 May 23 '15 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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