Title: get_post_count?
Last modified: August 19, 2016

---

# get_post_count?

 *  [vestaviascott](https://wordpress.org/support/users/vestaviascott/)
 * (@vestaviascott)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/get_post_count/)
 * I’d like to create a function that retrieves the post count for a given query.
   I don’t want to use get_posts obviously as its way to expensive for this purpose.
   However, that’s exactly what I’m having to use in absense of a get_post_count
   function.
 * My code is…
 *     ```
       global $post;
       $cat=get_cat_ID('mymenu');
       $catHidden=get_cat_ID('hidden');
       $myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => $NumberOfPostsToShow));
       $myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => -1));
       $myrecentpostscount = count($myrecentposts2);
       ```
   

The topic ‘get_post_count?’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [vestaviascott](https://wordpress.org/support/users/vestaviascott/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/get_post_count/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
