Let's say we have a taxonomy that goes three levels deep, eg. A > B > C
.
Next, we create a post and assign it to the "C" term.
In our case here, there will only ever be a single assignment; it's the event a thing took place at.
On the post's page, I want to output not just the assigned term, but the hierchical path to it. So, even though the post is assigned only to "C," I want to display "A > B > C" with links to the archive page for each of those terms along the way.
get_the_term_list
won't do it, and unless I've been using very bad search terms for an entire week, this is apparently very hard to do and every supposed solution I've managed to find is broken in some way. (One seriously required assumptions about the order of the taxonomy terms' database ID values.)
Here's one example that seemed to be addressing my exact case. That…simply outputs nothing in my installation, and var_dump($links_string)
produces something like "string(0) "";"
(Note there's two spots where "---" appears that should be collapsed to a single dash.)
Am I missing something?
Note things I don't want:
- To manually assign every term down the hierarchy. It's clearly not necessary. If you visit the archive page for "A" in the example structure, WordPress happily lists the posts in every sub-term, so obviously it has some way to see the hierarchy.
- If you've ever had clients, you know that this will just not get done.
- Breadcrumbs. These all start by listing the site root, and end with the post title, and are extremely difficult to clean up. The Yoast SEO implementation, for example, can be tricked into removing the root with blank data, and the post title with an external filter, but it's impossible to not end up with a trailing item divider.
- Also, every breadcrumb implementation I've found for some reason locks itself to providing a single function that displays a single configured taxonomy path (to the post). I have lots of taxonomies, and may eventually need to list other ones in a similar way, so need a generic function that lets me tell it what taxonomy to use.