Get the Actual Count of A Custom Loop’s Returned Posts

One of the nice things about creating a custom loop is being able to specify how many posts you want, using the showposts parameter, like so:

$feat_loop = new WP_Query( 'showposts=12&category_name=featured' );

However, it is possible that this query does not return a total of 12 posts (for example if you have less than 12 posts under the Featured category). To get the actual count of returned posts, you use this:

$total_returned_post = $feat_loop->post_count;

You may also like...

3 Responses

  1. May 11, 2011

    […] to WP Lover for the cool tip! If you enjoyed this article, please consider sharing it! tweetmeme_style = […]

  2. May 11, 2011

    […] to WP Lover for the cool […]

  3. May 18, 2011

    […] to WP Lover for the cool […]

css.php