Skip to content

Instantly share code, notes, and snippets.

@adamdoe
Created March 4, 2019 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdoe/52f3e22da0d383903c3c51b1f1f38c28 to your computer and use it in GitHub Desktop.
Save adamdoe/52f3e22da0d383903c3c51b1f1f38c28 to your computer and use it in GitHub Desktop.
WordPress SQL for post, category, user data
SELECT
p.ID,
p.post_author,
p.post_date,
u.display_name,
p.post_title,
p.post_content,
t.name
FROM wp_posts as p
INNER JOIN wp_postmeta as pm ON (p.ID = pm.post_id)
INNER JOIN wp_term_relationships as tr ON (tr.object_id = p.ID)
INNER JOIN wp_term_taxonomy as tt ON (tt.term_taxonomy_id = tr.term_taxonomy_id)
INNER JOIN wp_terms as t ON (t.term_id = tr.term_taxonomy_id)
INNER JOIN wp_users as u ON (u.ID = p.post_author)
WHERE p.post_type = 'post'
GROUP BY p.ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment