Title: How to select only published posts?
Last modified: August 18, 2016

---

# How to select only published posts?

 *  Resolved [deko](https://wordpress.org/support/users/deko/)
 * (@deko)
 * [20 years ago](https://wordpress.org/support/topic/how-to-select-only-published-posts/)
 * Basic SQL question:
 * A. `$qryPosts = "select count(*) -1 as ct from wp_posts where post_status = '
   publish';`
 * B. `$qryPosts = "select count(*) -1 as ct from wp_posts where post_status = 0;`
 * I’ve tried both, but no luck.
 * Looking at the table structure of wp_posts, I see this:
 * FIELD | TYPE
    post_status | enum | (‘publish’, ‘draft’, ‘private’, ‘static’, ‘
   object’, ‘attachment’)
 * I assume the enum is zero-based (?)
 * Why do neither of my queries work correctly?
 * How do I select a count of only published posts?
 * Thanks.

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

 *  [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [20 years ago](https://wordpress.org/support/topic/how-to-select-only-published-posts/#post-386480)
 * (A) works for me when run on the command line. How are you running the queries?
 *  Thread Starter [deko](https://wordpress.org/support/users/deko/)
 * (@deko)
 * [20 years ago](https://wordpress.org/support/topic/how-to-select-only-published-posts/#post-386483)
 * yes, my bad… A is in fact working.
 * thx

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

The topic ‘How to select only published posts?’ is closed to new replies.

## Tags

 * [wp_posts](https://wordpress.org/support/topic-tag/wp_posts/)

 * 2 replies
 * 2 participants
 * Last reply from: [deko](https://wordpress.org/support/users/deko/)
 * Last activity: [20 years ago](https://wordpress.org/support/topic/how-to-select-only-published-posts/#post-386483)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
