Skip to content

Instantly share code, notes, and snippets.

@salase
Last active February 17, 2017 23:01
Show Gist options
  • Save salase/e093c817e867170d510679fb06ede38c to your computer and use it in GitHub Desktop.
Save salase/e093c817e867170d510679fb06ede38c to your computer and use it in GitHub Desktop.
SELECT p.id, p.post_title, p.post_name, p.post_parent,
(select pp.post_name from wp_posts pp where pp.id = p.post_parent) as parent_name
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' and tt.term_id = <ID>
order by p.post_parent, p.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment