I have a query related to WordPress, which works perfectly in HeidiSql as a query, but I want to save category & tags in another custom database with PHP (also, I could save other fields into custom DB except category & tags).
Query:
SELECT DISTINCT
wp_posts.ID as ID, wp_posts.post_author as post_author, wp_posts.post_date as post_date, wp_posts.post_content as post_content, wp_posts.post_title as post_title, wp_posts.post_status as post_status, wp_posts.comment_status as comment_status, wp_posts.post_name as post_name, wp_posts.guid as guid, wp_posts.post_type as post_type, wp_posts.comment_count as comment_count,
(SELECT GROUP_CONCAT(wp_terms.name) from wp_term_relationships
LEFT JOIN wp_term_taxonomy ON(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)
WHERE wp_posts.ID = wp_term_relationships.object_id AND wp_term_taxonomy.taxonomy = 'category') as post_category,
(SELECT GROUP_CONCAT(wp_terms.name) from wp_term_relationships
LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms ON(wp_term_taxonomy.term_id = wp_terms.term_id)
WHERE wp_posts.ID = wp_term_relationships.object_id AND wp_term_taxonomy.taxonomy = 'tags') as post_tags
FROM wp_posts
WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post'