How can i get the row counts in query post like mysql count(*).

$obj_name = new WP_Query($args);

while ($obj_name->have_posts()) : $obj_name->the_post(); 

// here i want to predict looping counts


How can i do this.

$num = $obj_name->post_count; 

Reference: wp_query


The accepted answer here is wrong which is also confirmed in my situation. Please, compare from the referenced page:

$post_count The number of posts being displayed.

$found_posts The total number of posts found matching the current query parameters

This way, $post_count will show, for example, number of posts per page if there are more than one page of results. Only if total number is less than number of results per page it will match total amount.

The correct method to get total results number is:


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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