Title: Post type attachment count
Last modified: August 20, 2016

---

# Post type attachment count

 *  [Vergilius](https://wordpress.org/support/users/vergilius/)
 * (@vergilius)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/post-type-attachment-count/)
 * Hi everyone!
 * I’m looking for solution to count all attachment for current post type. Any ideas?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Vergilius](https://wordpress.org/support/users/vergilius/)
 * (@vergilius)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/post-type-attachment-count/#post-3053199)
 * Actually, I solved the problem. My solution:
 * $photocount=$wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM $wpdb->posts 
   WHERE post_type = ‘attachment’ AND post_parent IN (SELECT ID FROM $wpdb->posts
   WHERE post_type = ‘my_posttype’)”));
    echo $photocount;

Viewing 1 replies (of 1 total)

The topic ‘Post type attachment count’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Vergilius](https://wordpress.org/support/users/vergilius/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/post-type-attachment-count/#post-3053199)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
