Skip to content

Instantly share code, notes, and snippets.

@salase
Last active February 17, 2017 23:01
Show Gist options
  • Save salase/8e007abebb86cd7489a686492cdaf5e9 to your computer and use it in GitHub Desktop.
Save salase/8e007abebb86cd7489a686492cdaf5e9 to your computer and use it in GitHub Desktop.
SELECT p.id,tt.term_id
FROM (
SELECT p.id
FROM `wp_posts` p
join `wp_term_relationships` tr on p.id=tr.object_id and p.post_type='post'
join `wp_term_taxonomy` tt on tr.term_taxonomy_id=tt.term_taxonomy_id and tt.taxonomy='category' )
as p
JOIN wp_term_relationships tr ON tr.object_id = p.ID
JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id and tt.taxonomy = 'category'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment