Question

I have several nodes and several taxonomies, but only some nodes have taxonomy relationships.

enter image description here

My problem is that the taxonomy filter shows those terms too which don't have any node relationships at all, example:

enter image description here

So even if I don't have any nodes in "Category 1", the term will show up in the filter.

Is there a way to remove those taxonomy terms from the filter which have no content associated to them?

Was it helpful?

Solution 2

Managed to solve this with the combination of the Search API and Facets modules. Actually, it's not that complicated when you know what to do.

  1. Created a search index with the content of the categories.
  2. Created a new view with a Filter criteria with Content datasource (Content type).
  3. Finally, added a new facet where the source is the view display page I have created, and the field is the category.

OTHER TIPS

In Views, there is an option to specify a relationship and to require that relationship. You can find it in your View's config page, under Advanced. Just add a relationship to your taxonomy vocabulary and check the option to require the relationship.

The screen shot below is from the Content view that ships with Drupal 8, which is a great example of how to define a required relationship. enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top