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?
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.
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.