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
endwhile;
How can i do this.
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
endwhile;
How can i do this.
You must be logged in to post a comment.
Reference: wp_query
The accepted answer here is wrong which is also confirmed in my situation.
Please, compare from the referenced page:
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:
$obj_name->found_posts
.To get the total number of posts WP_Query returns use “found_posts”
Here is the example –
Use your custom post type name in place of ‘post’, you can also pass the category id too ( ‘cat’ => 4,)