0

I an using two taxonomies with private posts.

  1. category e.g. massage, travel
  2. location e.g. new-york-city, boston etc.

On a location page, I want to show categories that are relevant to that location. e.g. If I am on ?location=boston page I would find all the posts that are in boston, then I would find a list of categories in which these posts are categorized. I want this list to be displayed on top of location page.

Is there is a simple, built-in way to do all this?

  • You mean, when you're on Boston page, you want to get massage or travel, whatever is available in Boston? – Rutwick Gangurde May 3 '12 at 5:33
  • Yes. e.g. if boston has on 'massage' deals, it should show only 'massage' category. If it has 'travel' deals too then it should show 'travel' category too. – a_fan May 3 '12 at 6:29
1

In the_loop, just add this code...

<?php
    $cats = wp_get_object_terms(get_the_id(), 'category');
?>

Print_r $cats, it will have the list of the categories applied to this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.