Skip to content

Instantly share code, notes, and snippets.

@groggu
Created August 3, 2022 17:30
Show Gist options
  • Save groggu/067d7ba9aaadd1602417d9b9768080f2 to your computer and use it in GitHub Desktop.
Save groggu/067d7ba9aaadd1602417d9b9768080f2 to your computer and use it in GitHub Desktop.
List tags associated with wordpress posts
SELECT
wp_posts.ID AS 'Post ID' ,
wp_posts.post_title AS 'Post Title' ,
group_concat(
DISTINCT wp_terms.`name` SEPARATOR ', '
) AS 'Tags'
FROM
wp_term_relationships
JOIN wp_posts ON wp_term_relationships.object_id = wp_posts.ID
JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id
WHERE
wp_term_taxonomy.taxonomy = 'post_tag'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_type = 'post'
GROUP BY
wp_posts.ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment