Created
October 17, 2016 16:16
-
-
Save kaynenh/1fd46daad67d6287bde825ccb01da616 to your computer and use it in GitHub Desktop.
Wordpress Get All Categories in a Single Column by Post ID from MySQL
This file contains 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 p1.id, p1.post_title, p1.post_name, | |
(SELECT GROUP_CONCAT(wt.name SEPARATOR ', ') FROM wp_posts p2 | |
INNER JOIN wp_term_relationships r ON r.object_id=p2.ID | |
INNER JOIN wp_term_taxonomy t ON t.term_taxonomy_id = r.term_taxonomy_id | |
INNER JOIN wp_terms wt on wt.term_id = t.term_id | |
WHERE t.taxonomy="category" | |
AND p2.id = p1.id | |
) as categories | |
FROM wp_posts p1 | |
WHERE p1.post_status = 'publish' | |
AND p1.post_type = 'post' | |
GROUP BY p1.id | |
ORDER BY p1.post_date ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment