如何从wp_postmeta获取meta_key?

时间:2014-12-01 09:17:13

标签: mysql phpmyadmin

我使用此查询按类别名称获取帖子。它运作良好。现在我需要从meta_key获取sub_title。任何人都可以帮助如何在此查询中添加wp_postmeta。

`SELECT * 
FROM wp_terms
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships wpr ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
INNER JOIN wp_posts p ON p.ID = wpr.object_id
AND p.post_type =  'post'
AND p.post_status =  'publish'
AND name =  '$name'
ORDER BY p.post_date DESC`

提前致谢。

1 个答案:

答案 0 :(得分:0)

您必须添加另一个INNER JOIN,如下所示:

SELECT * 
FROM wp_terms
INNER JOIN wp_term_taxonomy 
ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships wpr 
ON wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
INNER JOIN wp_posts 
ON p.ID = wpr.object_id AND p.post_type =  'post' AND p.post_status =  'publish' AND name =  '$name'
INNER JOIN wp_postmeta wpm 
ON p.ID = wpm.post_id AND wpm.meta_key = 'subtitle'
ORDER BY p.post_date DESC