How can I set a filter to find nodes that have more than one term in a particular taxonomy vocabulary?
Note: The vocabulary allow unlimited values and is required field. So, nodes can have 1-∞ terms.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIn order to list down only those nodes of a specific content type that has more than one taxonomy term, I did the following and could only see nodes with more than one taxonomy term:
Create views with following filter criterias
A. Published=Yes
B. Content Type={Your Content type}
C. taxonomy term field:delta (= 1)
For "C" I have clicked on Add filter criteria, then searched for the (content type's) field that contains taxonomy term and selected the one that has :delta (i.e. my field name is field_taxonomy_term and I choose field_taxonomy_term:delta), Once you selected the delta of your taxonomy term field then choose the operator as is equal to and provide the value as 1 and save.
If a content type has exactly one taxonomy term then the delta field will never have index 1 but, will always have index 0. If a node has more than one taxonomy term (i.e. 2) then there is index 1 (Index 1 is always present for content types with more than one taxonomy term), that is why the filtering works.
See the screenshots for more info:
The page is configured to show only nodes with more than one taxonomy temr
The following attachment is configured to show all nodes (it is then attached to the page)
The result of the above page and attachment is as follow
In case you are interested in the view, here is the export code:
$view = new view();
$view->name = 'viewfornodewithtaxonomy';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'ViewForNodeWithTaxonomy';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Attachment display all nodes with any taxonomy terms';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '20';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: taxonomy terms */
$handler->display->display_options['fields']['field_taxonomy_terms']['id'] = 'field_taxonomy_terms';
$handler->display->display_options['fields']['field_taxonomy_terms']['table'] = 'field_data_field_taxonomy_terms';
$handler->display->display_options['fields']['field_taxonomy_terms']['field'] = 'field_taxonomy_terms';
$handler->display->display_options['fields']['field_taxonomy_terms']['delta_offset'] = '0';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'nodewithtaxonomy' => 'nodewithtaxonomy',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Content: taxonomy terms (field_taxonomy_terms:delta) */
$handler->display->display_options['filters']['delta']['id'] = 'delta';
$handler->display->display_options['filters']['delta']['table'] = 'field_data_field_taxonomy_terms';
$handler->display->display_options['filters']['delta']['field'] = 'delta';
$handler->display->display_options['filters']['delta']['value']['value'] = '1';
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'page display node with at least one taxonomy term';
$handler->display->display_options['path'] = 'viewfornodewithtaxonomy';
/* Display: Attachment */
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'nodewithtaxonomy' => 'nodewithtaxonomy',
);
$handler->display->display_options['filters']['type']['group'] = 1;
$handler->display->display_options['displays'] = array(
'page' => 'page',
'default' => 0,
);
$handler->display->display_options['attachment_position'] = 'after';
Don't forget to mark your question as resolved if the answer helped you.