4

In contextual filters, with

  • validator = taxonomy term
  • Filter value type = term ids separated by , or +
  • allow multiple values = true

Giving argument "1+2" works as espected: OR operator

Giving argument "1,2" works as "1+2": OR operator instead of expected AND operator

In both cases, conditions uses operator "IN":
WHERE (( (field_data_field_tags.field_tags_tid IN('1', '2') ) )AND(( (node.status = '1') AND (node.type IN ('flickr_photo')) )))

This is the contextual filter part of my view:

/* Contextual filter: Content: Tags (field_tags) */
$handler->display->display_options['arguments']['field_tags_tid']['id'] = 'field_tags_tid';
$handler->display->display_options['arguments']['field_tags_tid']['table'] = 'field_data_field_tags';
$handler->display->display_options['arguments']['field_tags_tid']['field'] = 'field_tags_tid';
$handler->display->display_options['arguments']['field_tags_tid']['default_action'] = 'empty';
$handler->display->display_options['arguments']['field_tags_tid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['field_tags_tid']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['field_tags_tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['field_tags_tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['field_tags_tid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_tags_tid']['specify_validation'] = 1;
$handler->display->display_options['arguments']['field_tags_tid']['validate']['type'] = 'taxonomy_term';
$handler->display->display_options['arguments']['field_tags_tid']['validate_options']['vocabularies'] = array(
  'tags' => 'tags',
);
$handler->display->display_options['arguments']['field_tags_tid']['validate_options']['type'] = 'tids';
$handler->display->display_options['arguments']['field_tags_tid']['validate_options']['transform'] = 0;
$handler->display->display_options['arguments']['field_tags_tid']['validate']['fail'] = 'empty';
$handler->display->display_options['arguments']['field_tags_tid']['break_phrase'] = 1;
$handler->display->display_options['arguments']['field_tags_tid']['not'] = 0;

How can I set a AND filter? I want to display contents with all values of tags.

2 Answers 2

2

I am not the best with deciphering exported settings, but I think you should remove that Contextual Filter and use "Content: Has taxonomy term ID" instead. Make sure you tick "Allow multiple values" under the More section. That will result in a chain of AND clauses in the WHERE for the view (well, it does in one that I just looked at).

4
  • I'm using contextual filter because I need to pass tids as argument in views_embed_view("gallery", "default", $gallery_arguments); and not exposing selection to user or making it static. Feb 9, 2012 at 19:49
  • Ok! "Contextual Filter" + "Content: Has taxonomy term ID" works! Thanks Feb 9, 2012 at 19:57
  • I think you are using the wrong contextual filter. I have a project where I am essentially doing the same thing, though I am using $view = views_get_view() and $view->set_arguments(explode(",", arg(X)); to generate it.
    – mpdonadio
    Feb 9, 2012 at 20:00
  • I had the same problem, this works. you should select Term IDs separated by , or + as Filter value type to make Allow multiple values works Mar 4, 2012 at 9:30
0

Set them as separate arguments, and it will filter to only things where both match.

1
  • I need to pass a variable number of tids. Like "1,2,3" or "1" or "5,7,96,36". Anyway... isn't this an unexpected behavior? Feb 9, 2012 at 9:53

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.