Wordpress - Counting the posts of a custom Wordpress loop (WP_Query)?

Correct way of getting the total number of posts is:

<?php $count = $custom_posts->found_posts; ?>

http://codex.wordpress.org/Class_Reference/WP_Query#Properties

Edit: acknowledging @Kresimir Pendic's answer as probably correct. post_count is the count of posts for that particular page, while found_posts is the count for all available posts that meets the requirements of the query without pagination. Thank you for the correction.


Manny linked correct documentation page but post_count is wrong. To get total number of posts WP_Query returns use "found_posts"

<?php

// The Query
$query = new WP_Query( $args );
$total = $query->found_posts;

Tags:

Loop