Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5530

fredehagelund91 on "get number of posts from category where meta_key is equal to?"

$
0
0

I'm trying to create a custom mysql query which count two things.

First of all it should count the number of posts in a category where the meta_key betting_status' value is not equal to "pending"

Then it should count the number of posts in a category where the meta_key betting_status' value is equal to yes.

So far i've done this but it does not output anything at all:

$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
";

Viewing all articles
Browse latest Browse all 5530

Trending Articles