2

On the product I created a "tags" taxonomy terms field. I have created a hundred "tags".

My products use around 10 "tags".

I created a pageview of my products with an exposed filter criterion "tags".

My problem :

The filter displayed on the product page displays all the terms. I only want to display the terms used by my products. How to do this ?

1 Answer 1

2

If doing it manually is acceptable you can do it on the Exposed Filter Settings by ticking the Limit list to selected items and then selecting only the 10 tags from the list above (hold Ctrl key to add to the selection). This works if you'll always or for long periods of time need only those 10 tags.


If you want Views to filter automatically and only show what's within the results without you having to choose the tags manually you have to use the Contextual filter instead of the Exposed regular Filter. Contextual filters are under Advanced options.

Add the Contextual filter for the same field "Tags" and configure it:
When the filter value is NOT available
Display a summary
Format List
Base path (you must enter the Page path if this isn't the first Page Display in your Views)
Display record count with link
More
Transform spaces to dashes in URL

Adjust the options for when the value is not available to your needs (Tags Taxonomy term etc.).

This way you get a list of term IDs that link through to a list of nodes tagged with those terms. That is because the Tags field only stores the TID information, not the term name. When you first load the page you only see the Summary, no results, you have to click through to see the results. But if you create the Summary as Attachment on a Page Display you can get it both ways, the Summary and the Results at the same time (keep the path the same).

But you probably want the term name to be displayed instead of the term ID. In that case remove that Contextual filter, and add the one for Taxonomy term Name, but you need a Relationship first for that information to become available.

Add a Relationship Taxonomy term referenced from field_tags (or whatever the field is called in your case), require it becasue you don't want summary results without tags!

Then add a Contextual filter Name from Taxonomy term Category, it will use the Relationship we created, and configure it like the above Contextual settings.


Alternatively you can use an additional module, this one did it in D7 but not yet ported to D8: Views Selective Filters.

Facets module provides an easy filtering interface from what's in the results.

2
  • For this question, manually, "hard coded", you're settingup for failure. People forget and adds an extra un-necessary step. Not sure how using a contextual filter answers the question when OP needs an exposed filter so users can pick the tag they want to filter by.
    – No Sssweat
    Commented Oct 28, 2020 at 12:57
  • Opting for the manual method can work depending on your particular business case. You could be building a short-term campaign for only 3 products that won't restock after sell-out, or similar. It is better to go with automatic if the number of tags used will expand organically. Contextual filter with the Summary acts like an Exposed filter as far as the user is concerned, it just looks different, it's links you click on instead of a form you submit.
    – prkos
    Commented Oct 28, 2020 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.