Skip to content

Instantly share code, notes, and snippets.

@crashncrow
Created May 15, 2021 18:44
Show Gist options
  • Save crashncrow/cef6c131e4a80a3dba43a40f4ff4f2b5 to your computer and use it in GitHub Desktop.
Save crashncrow/cef6c131e4a80a3dba43a40f4ff4f2b5 to your computer and use it in GitHub Desktop.

Revisions

  1. crashncrow created this gist May 15, 2021.
    14 changes: 14 additions & 0 deletions all-wordpress-posts.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    SELECT
    p.ID,
    p.post_title,
    p.post_name,
    p.post_status,
    p.post_date,
    GROUP_CONCAT(CASE WHEN tt.taxonomy = 'category' THEN t.name ELSE NULL END) categories,
    GROUP_CONCAT(CASE WHEN tt.taxonomy = 'post_tag' THEN t.name ELSE NULL END) tags
    FROM wp_posts p
    INNER JOIN wp_term_relationships tr ON ( tr.object_id = p.ID )
    INNER JOIN wp_term_taxonomy tt ON ( tr.term_taxonomy_id = tt.term_taxonomy_id )
    INNER JOIN wp_terms t ON ( t.term_id = tt.term_id)
    WHERE p.post_type = 'post'
    GROUP BY p.ID;