Created
August 15, 2025 12:58
-
-
Save loorlab/43e98bda31621c8b83fbbb5800a47783 to your computer and use it in GitHub Desktop.
Query - MySQL - WordPress | Display all Posts with Categories exclude pages and other content type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
p.ID, | |
p.post_title, | |
p.post_status, | |
CONCAT(u.option_value, '/', p.post_name, '/') AS permalink, | |
GROUP_CONCAT(t.name ORDER BY t.name SEPARATOR ', ') AS categories | |
FROM | |
wp_posts p | |
JOIN | |
wp_options u | |
ON u.option_name = 'siteurl' | |
LEFT JOIN | |
wp_term_relationships tr ON p.ID = tr.object_id | |
LEFT JOIN | |
wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id | |
AND tt.taxonomy = 'category' | |
LEFT JOIN | |
wp_terms t ON tt.term_id = t.term_id | |
WHERE | |
p.post_type = 'post' | |
AND p.post_status IN ('publish', 'draft', 'pending', 'private') | |
GROUP BY | |
p.ID, p.post_title, p.post_status, permalink | |
ORDER BY | |
p.post_date DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment