我想在此查询中添加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");
答案 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