Created
January 30, 2016 12:22
-
-
Save fer-ri/09eee040ac83892c251d to your computer and use it in GitHub Desktop.
Wordpress Term Query
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
-- Get All Category | |
SELECT wp_terms.* FROM wp_terms, wp_term_taxonomy | |
WHERE wp_terms.term_id = wp_term_taxonomy.term_id AND wp_term_taxonomy.taxonomy = 'category'; | |
-- Get all Post ID within "Uncategorized" Category | |
SELECT wp_posts.ID FROM wp_posts, wp_terms, wp_term_taxonomy, wp_term_relationships | |
WHERE | |
wp_terms.term_id = wp_term_taxonomy.term_id | |
AND wp_term_taxonomy.taxonomy = 'category' | |
AND wp_term_relationships.object_id = wp_posts.ID | |
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id | |
AND wp_terms.slug = 'uncategorized'; | |
-- Get all Post ID within "My Tag" Tag | |
SELECT wp_posts.ID FROM wp_posts, wp_terms, wp_term_taxonomy, wp_term_relationships | |
WHERE | |
wp_terms.term_id = wp_term_taxonomy.term_id | |
AND wp_term_taxonomy.taxonomy = 'post_tag' | |
AND wp_term_relationships.object_id = wp_posts.ID | |
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id | |
AND wp_terms.slug = 'my-tag'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment