Last active
November 22, 2021 13:36
-
-
Save petenelson/ddae23dc37926eb99e199dee25710ba7 to your computer and use it in GitHub Desktop.
WordPress SQL query by taxonomy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT wp_posts.* | |
FROM | |
wp_posts INNER JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) | |
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) | |
INNER JOIN wp_terms on (wp_term_taxonomy.term_id = wp_terms.term_id) | |
WHERE 1=1 | |
AND wp_term_taxonomy.taxonomy = 'taxonomy-slug' | |
AND wp_terms.slug = 'term-slug' | |
AND wp_posts.post_type IN ( 'post', 'page', 'cpt' ) | |
AND wp_posts.post_status in ( 'publish', 'future', 'draft' ) | |
ORDER BY wp_posts.post_date DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment