Select latest 2 articles, but only from given category

Try the below code- SELECT p.*, t.term_id FROM wp_posts p LEFT JOIN wp_term_relationships rel ON rel.object_id = p.ID LEFT JOIN wp_term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN wp_terms t ON t.term_id = tax.term_id WHERE tax.taxonomy = ‘category’ AND post_type = “post” AND post_status = “publish” AND t.term_id != 56 ORDER BY ID DESC LIMIT … Read more

WordPress Database Posts Table query

Turns out this works. global $wpdb; $postsTable = $wpdb->posts; $results = $wpdb->get_results( ‘SELECT * FROM ‘.$postsTable.’ WHERE post_type = “page” OR post_type = “post” AND post_status = “publish”‘);