WordPress – query to find all posts for a category

Find term_taxonomy_id for a category name

Use the following query to find term_taxonomy_id for a category name after replacing “Tutorials” with the category you want to use.

select wp_term_taxonomy.term_taxonomy_id from wp_term_taxonomy join wp_terms on (wp_term_taxonomy.term_id = wp_terms.term_id)
where wp_term_taxonomy.taxonomy = 'category' and wp_terms.name = 'Tutorials';

Find all posts for a term_taxonomy_id

select * from wp_posts join wp_term_relationships on (wp_posts.ID = wp_term_relationships.object_id)
where wp_term_relationships.term_taxonomy_id = 84;

Replace 84 with term_taxonomy_id value.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments