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've been using WP for years, but this is my first time with taxonomies, so I need a little bit of help.

Like in the question How to show a hierarchical terms list? I have a taxonomy called places, which contains a hierarchical list of places (first level for countries, second level for cities, etc...).

A post can have an associated place: for example, we could take Berlin (child of Germany, child of Europe).

Now, the output I want is something like this:

Where: Berlin, Germany, Europe.

I've tried some solutions, but none works. I'm pretty sure that there must be a simple and clean solution...

share|improve this question

2 Answers 2

up vote 2 down vote accepted

wp_get_object_terms will give you the term assigned to the post, you could then use get_ancestors to get an array of the parent's IDs, then get_term_by ID to get the names and slugs.

share|improve this answer

I found this really useful. Hope it could be also for you.


share|improve this answer

Your Answer


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

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