For example if I have a custom post type with the nested hierarchical custom taxonomy for "Countries"
parent - Asia
child - Japan
child - China
child - Thailand
If I just query [wpv-post-taxonomy type="category"] it will return ALL the categories e.g. Asia / China
Is there a way to limit the query to ONLY the top level (parent) taxonomy terms e.g. Asia
Hi, the wpv-post-taxonomy shortcode unfortunately is not flexible enough to handle that kind of filtering. Instead, you should create a View of the Countries taxonomy using the legacy Views editor, and add a taxonomy term parent Query Filter. If you cannot see the Query Filter panel, scroll to the top right corner of the view editor screen and click the "Screen Options" tab. You can turn on the Query Filter panel here. Then add a Query Filter based on the term parent, where the term parent is None. The results of that View will be top-level terms like Asia, in your case, since they have no parent terms.
If you are not familiar with the legacy View editor, you can enable it in Toolset > Settings > General. Look for the Editing Experience setting, and choose the option that enables both the Block Editor and the legacy editing experience if you'd like to have the option of either editor. Once you've activated the legacy experience, reload the page and you'll find a new main menu item Toolset > Views. You'll create and edit standalone Views from that dashboard.
I can help you implement the legacy Views editor if you need asssitance. We don't have much documentation available for that experience anymore since the push to Blocks.
Thanks. I am familiar with the Views Legacy editor. In fact I prefer to use that since I rarely use Gutenberg.
So I have a created a view [wpv-view name="home-page-post-teasers"] to output a list of the ten most recent posts of a custom post type.
The view contains the nested view [wpv-view name="parent-taxonomy-terms" cached="off"] which queries a custom taxonomy "regions" with the taxonomy parent filter:
Select taxonomy terms whose parent is None.
hidden link
The problem is that it outputs ALL the parent taxonomies rather than just the one which is relevant to the current loop item in "home-page-post-teasers".
Am I missing something?
The problem is that it outputs ALL the parent taxonomies rather than just the one which is relevant to the current loop item in "home-page-post-teasers".
If you also want to filter by the terms applied to the current post in the parent View, you must add another Query Filter, a taxonomy term filter. You will have one taxonomy parent filter (parent equals None) and one taxonomy term filter (set by the current post). I'm attaching a screenshot here to show this setup. The combination of both filters should produce the results you expect here.
Perfect! You nailed it.
Thanks for the help.