Skip to content

Instantly share code, notes, and snippets.

@crashncrow
crashncrow / all-wordpress-posts.sql
Created May 15, 2021 18:44
Mysql query to get all WordPress posts with categories and tags
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 )