Skip to content

Query แสดงหน้าที่ published ทั้งหมด และ tags และ categories

sql

SELECT
wp_posts.ID AS 'Post ID',
wp_posts.post_title AS 'Post Title',
CONCAT('https://your-site.com/',wp_posts.post_name) AS 'Post Url',
GROUP_CONCAT(DISTINCT wp_terms.name ORDER BY wp_terms.name SEPARATOR ', ') AS 'Post Tag',
GROUP_CONCAT(DISTINCT wp_categories.name ORDER BY wp_categories.name SEPARATOR ', ') AS 'Post Category'
FROM
wp_posts
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
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 AND wp_term_taxonomy.taxonomy = 'post_tag')
LEFT JOIN wp_term_relationships AS wp_category_relationships ON (wp_posts.ID = wp_category_relationships.object_id)
LEFT JOIN wp_term_taxonomy AS wp_category_taxonomy ON (wp_category_relationships.term_taxonomy_id = wp_category_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms AS wp_categories ON (wp_category_taxonomy.term_id = wp_categories.term_id AND wp_category_taxonomy.taxonomy = 'category')
WHERE
wp_posts.post_type = 'page'
AND wp_posts.post_status = 'publish'
GROUP BY
wp_posts.ID
ORDER BY
wp_posts.post_date DESC