Title: Count all posts made
Last modified: August 18, 2016

---

# Count all posts made

 *  Resolved [maerk](https://wordpress.org/support/users/maerk/)
 * (@maerk)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/)
 * Is there a simple way of getting the number of posts in the database?
 * At the moment I’m trying to use:
 * `$count = $wpdb->get_results('SELECT COUNT(*) FROM wp_posts');`
 * This isn’t working, because `$count` stays empty.
 * It must return a number, because I’m using this later on:
 * `$remainder = $count - 10;`

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

 *  [Mark (podz)](https://wordpress.org/support/users/podz/)
 * (@podz)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/#post-378687)
 * [http://www.lesterchan.net/portfolio/programming.php](http://www.lesterchan.net/portfolio/programming.php)
   
   The WP-stats plugin there has the right code (and a whole heap more). Might be
   of use?
 *  Thread Starter [maerk](https://wordpress.org/support/users/maerk/)
 * (@maerk)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/#post-378694)
 * Thank you, that’s perfect 😀 The code in question (for future folks) is:
 * `$count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts");`
 *  [designpastor](https://wordpress.org/support/users/designpastor/)
 * (@designpastor)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/#post-378696)
 * nice site maerk …
 * what did you use to do the photo gallery.
 * i like that ..
 * DesignPastor
 *  Thread Starter [maerk](https://wordpress.org/support/users/maerk/)
 * (@maerk)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/#post-378783)
 * Thank you! I use eSPG (enhanced Simple PHP Gallery)
 * [http://www.quirm.net/category.php?id=14](http://www.quirm.net/category.php?id=14)
 * It’s currently a bit broken since I completely destroyed it a while ago by overwriting
   the directory. What you see there is a temporary fix 🙁 I’m planning a redesign
   shortly, so it seems pointless to do anything too drastic to it just yet, but
   at least it works.

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

The topic ‘Count all posts made’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [maerk](https://wordpress.org/support/users/maerk/)
 * Last activity: [20 years, 1 month ago](https://wordpress.org/support/topic/count-all-posts-made/#post-378783)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
