Created
December 14, 2013 20:39
-
-
Save leoken/7964651 to your computer and use it in GitHub Desktop.
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 | |
post_name, | |
post_content, | |
Categories, | |
Tags | |
FROM | |
-- posts | |
wp_posts as p | |
-- categories | |
LEFT JOIN | |
(SELECT | |
object_id as cat_obj_id, | |
GROUP_CONCAT(cat_term.name) as Categories | |
FROM | |
wp_term_relationships AS cat_r | |
JOIN wp_term_taxonomy AS cat_tax | |
ON cat_r.term_taxonomy_id = cat_tax.term_taxonomy_id | |
JOIN wp_terms AS cat_term | |
ON cat_tax.term_id = cat_term.term_id | |
WHERE cat_tax.taxonomy="category" | |
GROUP by object_id) | |
as c | |
ON p.id = c.cat_obj_id | |
-- tags | |
LEFT JOIN | |
(SELECT | |
object_id as tag_obj_id, | |
GROUP_CONCAT(tag_term.name) as Tags | |
FROM | |
wp_term_relationships AS tag_r | |
JOIN wp_term_taxonomy AS tag_tax | |
ON tag_r.term_taxonomy_id = tag_tax.term_taxonomy_id | |
JOIN wp_terms AS tag_term | |
ON tag_tax.term_id = tag_term.term_id | |
WHERE tag_tax.taxonomy="post_tag" | |
GROUP by object_id) | |
as t | |
ON p.id = t.tag_obj_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment