如何在没有使用WordPress本机api的情况下使用纯SQL检索类别下的帖子get_pages
?
我的Wordpress表wp_terms
包含名为“餐馆”的术语。
我想把这个职位只列在这个学期。
以下查询是否正确?
我说的对吗JOIN
零件?
SELECT p.ID AS postId,
p.post_name,
p.post_title,
p.post_content,
p.post_excerpt,
p.post_status,
p.post_type,
p.post_author,
p.guid,
p.post_modified_gmt
FROM `wp_posts` AS p
LEFT JOIN `wp_term_relationships` AS tr ON p.ID = tr.object_id
LEFT JOIN `wp_term_taxonomy` AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE post_type=\'place\' AND post_status=\'publish\' AND tt.term_id = 11
ORDER BY postId DESC
SO网友:Toir
SELECT p.ID AS postId,
p.post_name,
p.post_title,
p.post_content,
p.post_excerpt,
p.post_status,
p.post_type,
p.post_author,
p.guid,
p.post_modified_gmt,
(SELECT group_concat(t.name SEPARATOR \', \')
FROM wp_terms t
LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
LEFT JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = \'category\' AND p.ID = tr.object_id
) AS category
FROM `wp_posts` AS p
LEFT JOIN `wp_term_relationships` AS tr ON p.ID = tr.object_id
LEFT JOIN `wp_term_taxonomy` AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE post_type=\'place\' AND post_status=\'publish\' AND tt.term_id = 11
ORDER BY postId DESC