Wordpress MySQL查询帖子类型

时间:2018-09-12 08:49:39

标签: sql wordpress

我想在此查询中添加post_type选项。我该怎么办?

$state = $wpdb->get_results(" SELECT meta_value AS state, COUNT(post_id) AS count FROM {$wpdb->postmeta} WHERE meta_key = 'personal_nation' GROUP BY state ORDER BY state DESC");

1 个答案:

答案 0 :(得分:-1)

尝试此查询

SELECT meta_value AS state, COUNT(post_id) AS count, post_id 
FROM wp_postmeta WHERE meta_key = 'personal_nation' 
AND post_id in(select ID from wp_posts where post_type="post") 
GROUP BY state ORDER BY state DESC