I have created a view, where I display two content types. Both of them have field "Country". So in my view I want to display only nodes related to three particular countries, but additionally I want to add filter, so that the user is able to see content only for one country out of the three.

The problem is that when I specify in "Filter criteria" show nodes only for these three countries it works, but when I make this filter "exposed" the view renders absolutely all nodes.

At the same time I want my exposed filter to have only the 3 countries available available.

  • perhaps there is another view that messes the view up ? or describe in more detail your view / content type setup ... – GiorgosK Aug 21 '18 at 13:42
  • I have two content types. Both of them have field "Country" (the filed is re-used) what is the reference to taxonomy term. I need to create a view, where I need to display the nodes (Image, Title, Description) of this two content types, which are related only to three countries – User88002 Aug 21 '18 at 14:32

An exposed filter has no effect by default, so your simplest solution is to add another filter that is not exposed that limits the view to just the countries you want.

It's a useful trick with views to combine exposed and not-exposed filters and sorts.

  • When the view is loaded it seems right, but it disabled the filter. I can not filter the results depending on the country – User88002 Aug 21 '18 at 14:24
  • I don't know exactly what version of Drupal you are using but I just created a view from scratch in Drupal 8.5.5, following these instructions but using content types and taxonomies already existing on the site, and it worked exactly as expected. When you say it disabled the filter, please explain exactly what you mean. – Alfred Armstrong Aug 22 '18 at 8:44

Here is a setup that does not seem to create any trouble. The country is a taxonomy term field attached allowing only 1 country to be specified per node.

When the filter is exposed you can specify the countries to be displied/filterable and you can also limit the list to those countries

Here is a working setup

enter image description here

and here what you will see vising the page of this view

enter image description here

only the specified countries are displayed and it works as it should

  • If I do it the same way, it also works. But then in filter it shows all taxonomies for country field, But I need just three countries in the filter. And that's why I also check "Limit list to selected items" and this breaks the view – User88002 Aug 21 '18 at 13:30
  • Make that known in your question please – GiorgosK Aug 21 '18 at 13:32
  • With all that setting, when I apply the filter /collections?field_country_target_id=968 it returns me again all existing nodes – User88002 Aug 21 '18 at 14:30
  • perhaps you have a module that messes with your view ... try to do this on a new drupal 8 installation or try to disable all modules that might be doing harm. – GiorgosK Aug 21 '18 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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