Skip Navigation

[Resolved] Display subcategories within a parent category using archives

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#627858
CATEGORY.png

Hi all, I would need to create an archive that displays the parent categories, and after clicking one of these parent categories, you enter a section where I only see the sub-categories of that particular parent category

#628309

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

view 1 settings.png

Hi there

Firstly, please note that you are posting in the Community Forum for users of the free Types plugin. As a Toolset customer you can and should post in the Technical Support forum which we prioritise and where you should receive speedier service.

This would be reasonably straightforward, except Views is missing some of the functionality you would use to produce this, and you will need to plug the gap with some custom code.

Let me outline what is required.

In my example I have created a custom taxonomy "places", the top level terms being countries, and the next level terms being cities of that country.

So you will need to publish two normal WordPress pages to insert the Views which generate the required output are inserted, in my case places-countries and places-cities.

Now I create a taxonomy View to display the top-level taxonomy terms.

So this View will query my places custom taxonomy, and it includes a Query Filter to only show terms with no parent (i.e. the top-level terms).

In my Loop Output section I am going to display these top level terms and link them to the second page (places-cities) where I will display the second-level terms, like so:

		<wpv-loop>
          <a href="[wpv-bloginfo show='url']/places-cities/?place=[wpv-taxonomy-id]">[wpv-taxonomy-title]</a>
		</wpv-loop>

Note that I pass the ID of the current top-level term to the target page as a URL parameter "place".

I insert this View into the first page, and then proceed to make the second View.

This will also display my custom taxonomy terms, but this time we need a Query Filter where the parent is set by the URL parameter "place" added to our links in the first View.

But... this is the missing feature, you can only manually select specific terms for the parent filter in a taxonomy View, the option to use a shortcode attribute or URL parameter is missing.

Which is where the need for custom code arises.

You will need to use the wpv_filter_taxonomy_query hook to modify the query and set the filter term ID using the value retrieved from the URL parameter (https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query).

Is that something you are able to do? In your View choose one of the top level terms (e.g. France, in my case) which will be applied to all of these second View instances. Then use the wpv_filter_taxonomy_query hook to override that with the term id from the URL parameter.

If you need help with that let me know.

The forum ‘Types Community Support’ is closed to new topics and replies.