Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What is the relationship between categories and cities? Are you only trying to pull posts that contain both category and city? –  Howdy_McGee May 9 at 15:46
    
I am trying to pull the terms of posts that match the specified province and city custom fields on the post. The idea is that only terms related to the province and category should be displayed with a count next to them. I am not trying to get all terms just ones that match the custom field criteria specified. –  Camrin Parnell May 11 at 0:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.