SQL query to extract only the “current” wp_posts?

Rather than constructing query from scratch, it is easier to see what exactly is WordPress querying when API function is used:

get_posts(array(
             'numberposts' => -1,
         ));

var_dump( $wpdb->last_query );

Gives following SQL:

SELECT wp_posts.* FROM wp_posts 
WHERE 1=1 
AND wp_posts.post_type="post" 
AND (wp_posts.post_status="publish")
ORDER BY wp_posts.post_date DESC

Leave a Comment