Title: Display Custom Post Type Post Count
Last modified: August 20, 2016

---

# Display Custom Post Type Post Count

 *  [João Sardinha](https://wordpress.org/support/users/johnsardine/)
 * (@johnsardine)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/)
 * Hello,
 * i need to output the number of posts in a custom post type so i can later output
   other stuff based on the number of posts.
 *     ```
       <?php query_posts(array('post_type' => 'galleries')); ?>
   
       <?php if ( have_posts() ) : ?>
       <?php while ( have_posts() ) : the_post(); $count++; ?>
   
       <?php echo $count; ?>
   
       <?php endwhile;?>
       <?php endif; ?>		
   
       <?php wp_reset_query(); ?>
       ```
   
 * So far i have that, but it only outputs me a number per post, which is normal,
   but i want a variable that contains the number of posts in that post type so 
   i can use conditional comments later
 * Any help?
 * Thank you

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

 *  [vankaa](https://wordpress.org/support/users/vankaa/)
 * (@vankaa)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2136660)
 * Try `<?php wp_count_posts( $type, $perm ); ?>`
 *  Thread Starter [João Sardinha](https://wordpress.org/support/users/johnsardine/)
 * (@johnsardine)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2136666)
 * Thank you, that seems to be what im looking for, however when i try
 *     ```
       <?php
       $count_posts = wp_count_posts('posts');
       echo $count_posts;
       ?>
       ```
   
 * it outputs an error:
 * Catchable fatal error: Object of class stdClass could not be converted to string
   in mysite/index.php on line 92
 *  [vankaa](https://wordpress.org/support/users/vankaa/)
 * (@vankaa)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2136772)
 * If you want all posts, than leave it default or write ‘post’. If you want something
   specific like ‘post_type’ => ‘galleries’, than write it in. You can read the 
   [documentation](http://codex.wordpress.org/Function_Reference/wp_count_posts)
 *  Thread Starter [João Sardinha](https://wordpress.org/support/users/johnsardine/)
 * (@johnsardine)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2136886)
 * i am aware of that thank you, but it outputs the above error when i try
 *  [jkulig](https://wordpress.org/support/users/jkulig/)
 * (@jkulig)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2137054)
 * wp_count_posts() returns an object. Make sure you reference one of its properties:
 *     ```
       <?php
       $count_posts = wp_count_posts('posts');
       echo $count_posts->publish; //
       ?>
       ```
   

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

The topic ‘Display Custom Post Type Post Count’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [count](https://wordpress.org/support/topic-tag/count/)
 * [display](https://wordpress.org/support/topic-tag/display/)
 * [number](https://wordpress.org/support/topic-tag/number/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [jkulig](https://wordpress.org/support/users/jkulig/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/display-custom-post-type-post-count/#post-2137054)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
