Skip Navigation

[Resolved] Displaying Term Meta Fields on a View

This support ticket is created 3 years, 10 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by Timothy 3 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1916251

Hi,

I have a cpt "Books" with a taxonomy "Book Categories" and have created a View displaying the Books with the taxonomy filter to create my Book Search page which is working fine:

hidden link

With some custom js I've manage to also output the name of the selected Book Category above the search results. I'd also like to output some Book Category term meta fields that I created, but after searching of support tickets I cannot find a solution.

I thought I could create a View displaying the Book Category Taxonomy and with the query filter "Terms with ID set by the shortcode attribute" then place this view within the Book View and somehow grab the taxonomy ID of the selected taxonomy of the filter... Is this possible?

I already can grab the name of the taxonomy so maybe I could get the ID from the name?

Tim

#1916591
Screen Shot 2021-01-24 at 11.27.58 AM.png

I thought I could create a View displaying the Book Category Taxonomy and with the query filter "Terms with ID set by the shortcode attribute" then place this view within the Book View and somehow grab the taxonomy ID of the selected taxonomy of the filter... Is this possible?
Hello, there are a couple of problems in this approach.
1. The current search View uses AJAX to update its results whenever the filter(s) are changed. There is no AJAX API for retrieving View results, so you would not be able to get the updated taxonomy term results when a filter changes like this. The custom search View would have to be configured to require a page refresh and the necessary updated URL parameters. However...
2. A taxonomy search filter in the main View will not include the term ID necessary for filtering a taxonomy View. The filter will include the term slug as its value, rather than the term ID. So you could access that selected term slug using the shortcode wpv-search-term, but not its ID. That is a problem because in the current software a taxonomy View cannot be filtered by term slug, only by term ID (screenshot). You would need some type of custom code with our PHP API to apply a conversion from the term slug to the term ID for the View filter to process.
3. You cannot create taxonomy Views in the Block Editor, but it looks like you're using legacy Views anyway so that's probably not a major concern for you.

Another option I would consider is to not filter the taxonomy View by term, but to include the results for all terms upon page load. Hide them all using CSS, then use custom JavaScript to pull data out of that hidden View and display it above the main results whenever the filter is modified. I assume it would be similar to how you're setting the headline above the results, so you probably have much of the necessary code structures written already.

#1920347

Thanks for all that detail. I'd really prefer to keep the Ajax search results, so I think I will try the css option. My only concern would be that there are several hundred book categories so including all those terms could get heavy and bog things down. Or would that not really be a concern?

#1920453

I would try it and see, it's hard to guess about this because there are many different variables involved like the server setup and database engine, as well as front-end variables like how the results are displayed. Views implements a caching layer on the database, so some of the strain of that query on the server could be limited by caching the term View. Views caching is implemented by default, so there's nothing you need to do to activate it. The situations that disable caching are explained here: https://toolset.com/documentation/legacy-features/views-plugin/how-to-use-views-parametric-search-on-large-sites/
As long as you avoid these cache invalidating situations, Views caching will be in play. You can also install a plugin like Query Monitor to examine the queries involved to see if the overall page load time is impacted severely, or run tests with a system like https://www.webpagetest.org/ with and without the full term View.

#1922165

My issue is resolved now. Thank you!