Skip Navigation

[Resolved] Display Taxonomy links and when clicked filter current view

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a custom search View with several filters. In the results, I would like to display posts and include taxonomy term links. Instead of linking to the term archive, I would like to use the links to further filter the custom search View.

Solution: This would require advanced JavaScript. If you're not concerned about maintaining the existing filters, you can construct your own custom links that use the proper URL parameter structure.

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Jan Thielemann 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1101735

Tell us what you are trying to do?
I have a view in which I show a search at the top and posts of a custom post type in the loop. Each post is displayed as a card with title and terms of a taxonomy associated with this post (which is also one of the filters in the search).

Is it possible that when I click on the term, instead of going to the archive page for that taxonomy, to set the selected term as the filter in the search and do a ajax reload or reload of the current page/view?

#1101804

Hi, it depends on the other search criteria in this View and whether or not you want to maintain them after clicking a term. If you don't care about maintaining the other search criteria and you simply want to filter by that term, create a View of this taxonomy, filtered by term, where the term is set by the current post. In the Loop editor, create a custom link tag for each term, and apply the correct URL parameters to navigate to this page with the term filter already applied. Something like this:

<a href="/your-search-page?wpvsometaxslug=[wpv-taxonomy-slug]">[wpv-taxonomy-title]</a>

Insert this View in your View of posts instead of the wpv-post-taxonomy shortcode.

If you want to maintain the current search parameters and add a term filter, there's not an easy way to do this without some advanced JavaScript. Basically there is no JavaScript API for manipulating search filters on-the-fly, so I don't have any code samples available to help you programmatically update the View with AJAX. So that leaves triggering a full page refresh as the only option. To do that, you would need to be able to append the desired term parameter to the current URL. With several search parameters, and the possibility of supporting multiple terms in the same taxonomy filter, there's no easy way to determine the correct URL to apply to each term link. In order to be accurate, you would need to use JavaScript to inspect the current URL, break apart the search parameters, add or append to the term parameter, and then reassemble the params and apply the updated URL to each link. It may be possible, but unfortunately it's not something I have as a cut-and-paste solution.

#1102320

Hi Christian,
thank you very much for the response. It was exactly what I needed to disassemble the wall in my head. I think I will go with the simple solution first and track how it is accepted. I still could write the necessary JavaScript later on and I think a full refresh would be good enough.