我试图创建一个自定义的mysql查询,它计算了两件事。
首先,它应该计算meta_key betting_status'的类别中的帖子数量。值不等于"待定"
然后它应该计算meta_key betting_status'的类别中的帖子数量。值等于是。
到目前为止,我已经完成了这项工作,但它根本没有输出任何内容:
$wombo_query = "SELECT count(DISTINCT $wpdb->postmeta.post_id) FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) AND
WHERE $wpdb->postmeta.meta_key = 'betting_status'
AND $wpdb->posts.meta_value = 'yes'
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->term_taxonomy.term_id = 106
";
答案 0 :(得分:1)
试试这个。
SELECT count(DISTINCT wp_postmeta.`post_id`)
FROM wp_posts
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
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)
WHERE wp_postmeta.meta_key = 'betting_status'
AND wp_postmeta.meta_value = 'yes'
AND wp_posts.post_status = 'publish'
AND wp_term_taxonomy.taxonomy = 'category'
AND wp_term_taxonomy.term_id = 106;
由于我的数据库中没有与你的数据库相同的值,因此我返回0行,但它确实执行了。
干杯! = C =