Title: Quick post count using WP_Query( $args )?
Last modified: August 20, 2016

---

# Quick post count using WP_Query( $args )?

 *  Resolved [ixwa](https://wordpress.org/support/users/ixwa/)
 * (@ixwa)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/quick-post-count-using-wp_query-args/)
 * Trying to get a total count of all posts matching a query **before** running 
   the loop. I know it’s possible to first run a loop with $i++ to tally the results,
   but this means running the loop twice (presumably slower).
 * Anyone know if there’s a quick WP_Query() parameter for getting the equivalent
   of a mySQL COUNT() during SELECT?
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/quick-post-count-using-wp_query-args/#post-2120428)
 * Do you really need the count before the query, or just before you display the
   results?
 * If the latter, you can just use the found_posts property of the query. For example,
 *     ```
       <?php
       $args = array(
          'posts_per_page' => 5,
          'post_type' => 'post',
       );
       $myquery = new WP_Query($args);
   
       echo "<h2>Found: $myquery->found_posts</h2>";
   
       ?>
       ```
   
 *  Thread Starter [ixwa](https://wordpress.org/support/users/ixwa/)
 * (@ixwa)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/quick-post-count-using-wp_query-args/#post-2120520)
 * Actually no, this is exactly what I was looking for. I needed the full count 
   of matching results before starting the loop.
 * Thanks very much.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Quick post count using WP_Query( $args )?’ is closed to new replies.

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [matching](https://wordpress.org/support/topic-tag/matching/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [ixwa](https://wordpress.org/support/users/ixwa/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/quick-post-count-using-wp_query-args/#post-2120520)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
