I am having trouble with the proper configuration of passing multiple taxonomy term selections through a page (which calls a view) and uses contextual filters to display only nodes that have, in this case, categories which match the ones i've multiple selected in the node.

I have a node with a taxonomy multiple select box (category). I select two categories.
I have a page that is used for that node's specific content type. It calls a view.

Presently that view is configured such that the view's contextual filter, as it is presented in pages, is:
CONTENT: HAS TAXONOMY TERM ID
and I select 'category'.

In views i have set up a contextual filter with these specs:
Content: Has taxonomy term ID
Specify validation criteria - Validator: taxonomy term
filter value type: term name converted to term id (I could use others, a few seem to work - my gut tells me I need the ..Terms ID separated by, or +)
and then undre more i've selected "allow multiple values"

I think the issue is in passing the arguments from the page to the view, so I thought I would try creating custom arguments - but this is completley lost on me.

its worth noting that there is ONE other contextual filter I pass before this - but it's working just fine because I dont need multiple values.

Any support would be greatly appreciated,
Thanks

CommentFileSizeAuthor
#16 view-bug.png31.62 KBshahgm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mhaamann’s picture

Category: support » bug

Marking this as a bug.
I am also experiencing this.

Anonymous’s picture

Same here. Trying to list users and using UID as contextual filter. 1 UID works just fine but when trying with multiple -> no records.

Actually SQL query won't event get executed with multiple filters (1,2,3 or 1+2+3).

Fazula’s picture

As a beginner I find it hard to understand exactly how to do this, any help regarding best practices when adding more than one taxonomy term to a contextual filter will be appreciated.

othermachines’s picture

The configuration below allows me to match on (for example) mysite.com/publications/term/4 (just 4), or mysite.com/publications/term/4+7 (4 OR 7) or mysite.com/publications/term/4,7 (4 AND 7). So far so good, anyway.

Drupal 7.x, Views 3
Display type: Page
Path: "publications"

First contextual filter: Global: Null

  • When the filter value is NOT in the URL: Provide default value
  • Type: Fixed value
  • Fixed value: term

Second contextual filter: Content: Has taxonomy term ID

  • When the filter value IS in the URL or a default is provided: Specify validation criteria
  • Validator: Taxonomy term
  • Vocabularies: checked all vocabularies that I wanted to include
  • Filter value type: Term IDs separated by , or +
  • Action to take if filter does not validate: Display contents of "No results found"
  • Reduce duplicates: checked
  • Allow multiple values: checked (this is under "More")

I could not get this to work with filter value type "Term name converted to term id" no matter what I tried. Not convinced it's a bug but it's certainly counter intuitive.

Cheers -

chrsnlsn’s picture

I find it's helpful to find a couple test term id's to make sure a contextual filter is working so if I'm setting up a contextual filter for Content: Tags (field_tags).
I choose 'Provide default value' Type PHP Code. Then just throw a couple static tid's in there like so

return "15+19";

at least this will let you know if the view is spitting out the values you expect given known tid's

coolhandlukek2’s picture

Subscribe - problem for me too

Eleine’s picture

Same problem here. I have one contextual filter for term id (raw value from URL) which works perfect as long as I do not add my second filter, which is a PHP generated multiple-value argument which should negate nodes that has already been rendered on the page.

Is this bug tracked somewhere else? I find it strange that only the few people abouve should have reported this.

Edit: After changing "raw value from URL" to taxonomy id and then sending the id from a pages context, it works. The PHP output should of course not interfere with the raw value from URL option, but this seems to be a workaround in some cases when raw URL value can be avoided.

ssoulless’s picture

Issue summary: View changes

Im experiencing the same of @othermachines if I pass 4,5 term ids as arguments or 4+5 it works ok but I could not make it work with term name. if you choose "term name converted to term ID" it works only with one sime taxonomy name for example if I pass "taxonomy name 1" as argument it works ok, but if I do something like "taxonomy name 1+taxonomy name 2" or "taxonomy name 1,taxonomy name 2" it just does not work.

So how to use multiple values with term names as arguments?

vchen’s picture

#4 worked for me! However, I changed it a bit to fit my needs. My contextual filter did not come from the URL so I didn't need to bother with the Global:Null filter.

Also, just by habit, I filled in When the Filter Value is NOT available section
Provide default value
Type: Taxonomy term ID from URL
Load default filter from term page
load default filter from node page that's good for related taxonomy blocks
Limit terms by vocabulary: select your vocab
Filter to items that share any term

jim005’s picture

any update on this ? I'm facing to this same bug. :-(

xandermar’s picture

+1 - same problems here. I experience with Views page (path: name/%/%). Trying to pass two variables, selected "RAW VALUE FROM URL" and selecting the PATH COMPONENT. Tried position 1, 2, 3, etc... nothing worked - defaulted on the first variable every time. For example, if path was "name/1/2" and I needed the variable "2", I'd select RAW with PATH COMPONENT "3" - didn't work ("Use path alias" unchecked). Views kept using the PATH COMPONENT 1 regardless of my changing it.

othermachines’s picture

Hey, @xandermar. FWIW, I always have "Use path alias" checked when retrieving arguments from the URL.

xandermar’s picture

@othermachines - Thanks.. But, I tried both with "Use path alias" (checked and unchecked). Doesn't work either way... :(

kimjanssens’s picture

@xandermar Try:
NOT
- unfiltered value from url
- pathcomponent -> 1 or 2
- use path alias
IS
- Validationcriteria -> taxonomy term
- termname to termID

scaballeronavia’s picture

Hi from Bolivie, I have a solution, it works well for me.

Add context filter:

- Content: You taxonomy term ID (with depth)
- Allow multiple values check
- Filter value type: separated by + or

Great!

shahgm’s picture

Version: 7.x-3.5 » 8.x-3.x-dev
Issue tags: +views filters, +views taxonomy term
FileSize
31.62 KB

I am having the same problem using Drupal 8.0.3 and no luck. I want to show two tags of the same fields i.e. Market = Enterprise OR Market = "user selection through expose filter(one value)".

I tried to design query with no luck as shown in the image. Also, tried by using allowing multiple selection. Then select Enterprise and some other selection, but no luck. Any help?

In 2nd option when i select one value, i get result for that selection. Upon selecting multiple values, start getting no result.

Thanks,

shahgm’s picture

in filters i want to add additional tag on top of exposed filter for taxonomy term. For example, in following image when user select particular market for example: Richmond, i want to show table with content that has Richmond or Enterprise tag on them.

Any suggestion to fix or work around would be greatly appreciated.

https://www.drupal.org/files/issues/view-bug_0.png

Thanks,
Shah

Lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.0.x-dev
Component: Miscellaneous » views.module
Category: Bug report » Support request
Priority: Major » Normal
Issue tags: -views filters, -views taxonomy term

Looks more like a support request then a bug at first glance, moving to the right queue

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

KD Eric Depta’s picture

I have the same bug using a 'Fixed' default argument. No matter if you enter the values separeted by '+' or ',' the results are the same. The query does not change. It allways makes an IN (..,..,..) statement out of it.
In addition the query setting Distinct is not working as well.

erichomanchuk’s picture

@KD Eric Depta If you are using the contextual filter Content: Has taxonomy term ID (with depth) then the query will always us an IN operator for the statement. If you read the help text under the Allow multiple values if states "... Due to the number of JOINs it would require, AND will be treated as OR with this filter." so the multiple-value handling options - Filter to items that share all terms - Filter to items that share any term - Will both function only as an OR, which is somewhat confusing.

jzavrl’s picture

If anyone else is still having an issue with this, here is how you make it work.

Under "When the filter value is available or a default is provided" you need to select:

  • Specify validation criteria
  • Taxonomy term ID
  • One or more IDs separated by , or +

And then under "More" check "Allow multiple values", after that you can use multiple IDs such as 1+2 or 1,2.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

axooh’s picture

I have a similar issue. I configured the contextual filter as mentioned in the last comment, but the view shows only results for the first taxonomy.

For example for the path /view/1+2 only the elements with taxomony 1 are shown.

hudri’s picture

This is definitely a bug, contextual filters with multiple values and operators don't work as expected. It is not related to entity references or taxonomy terms, also multi-value base fields such as integers or plain texts can't be filtered correctly.

  • Single value contextual filters work as expected
  • Single values still work correctly after enabling "Allow multiple values" in contextual filter window
  • Providing two filter values for the contextual filter gives duplicated results when the node has both values in the filtered field
  • Multiple value contextual filters with AND operator "value_1,value_2" gives same result as contextual filters with OR operator "value_1+value_2"
  • Enabling "When filter value is available ... Specify a validation criteria for multiple arguments" (e.g. when filtering by taxonomy term id) does not help
  • When enabling "When filter value is available ... Specify a validation criteria for multiple arguments" and disabling "Allow multiple values" only the first filter value is used, no matter if using "id1+id2" or "id1,id2"
  • Adding relations to the view (e.g. when filtering by taxonomy) does not help
hudri’s picture

Category: Support request » Bug report

(changing back to bug report)

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rogerpfaff’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wrg20’s picture

+1 following

rogerpfaff’s picture

@wrg20 You can follow an issue with the follow function in the right column of every issue. Right below the grey box.

portulaca’s picture

I can confirm symptoms from #26.

So it seems that the OR operator "value_1+value_2" is working as expected, but there is no way to get the AND operator "value_1,value_2" working, it's just copying the OR case.

I'm seeing the same behavior in D7.

ccarrascal’s picture

I am having the same issue here, same as #26 and #34. I have tried also recommendations from #23, but I couldn't get it to work that way either.
I am always getting an OR instead of and AND.

I am using 8.6 core at this time.

liquidcms’s picture

Slightly different issue; but likely related. If i allow multiple and use "taxonomy term name" validation; then if i pass multiple with +, i get no results. In other words it appears to try to validate the entire string "term1+term2".

This is with 8.7.10

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ianchan’s picture

@ccarrascal - how did you get the OR to work. Multiple taxonomy IDs does not work for me in contextual filter.

ccarrascal’s picture

@ianchan, OR was working for me just following the steps in #23

dmezquia’s picture

#23 works fine for me, I just think the "more" checkbok should be more visible to see it better.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
robert_t_taylor’s picture

Thanks, @jzavrl! I can confirm that #23 works on Drupal 9.2.1.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.