I have a custom post type called "coupons". These coupons can then be drilled down by "city". City is a custom field that is defined for each individual "coupon". I am then trying to modify a sidebar widget so it will only show the distinct categories related to the specific queried cities result set, as opposed to all coupon categories. I would then need to display a count that would show how many of the returned coupons belong to the specific category.
So far the query returns all coupon categories (and the coupon count), not just the ones that belong to the specific coupon category.
SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('coupon_category', 'coupon_tag', 'stores', 'coupon_type') AND tr.object_id IN (430, 618) ORDER BY t.name ASC
Any help would be greatly appreciated.