1

I have two taxonomy term vocabularies:

  1. Model
  2. Parts

A part is associated with a model via a taxonomy term reference field on the Parts term. The idea is when a user clicks on a model and is viewing the taxonomy term page, they should be able to see all the parts that reference that model.

What I want is something similar to the views contextual filter "Content:NID" and "Content ID from URL".

All of the Views contextual filters and fields appear to be very focused on nodes, so I'm guessing Views just doesn't have this feature yet.

EDIT: Here is the query I want:

SELECT entity_id from taxonomy_term_data as tt
JOIN field_data_field_part_model as pm ON tt.tid = pm.field_part_model_tid
WHERE pm.field_part_model_tid = CURRENT_TERM_TID_GOES_HERE

EDIT:

Here is the view that I am using. Instead of finding the parts that reference this model, it finds every single part that has anything entered in field_parts_model. A part can be compatible with more than one model, and so field_parts_model is multiple cardinality, maybe that is messing it up? This doesn't make any sense.

$view = new view();
$view->name = 'related_terms';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Related Terms';
$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['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['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'entity';
$handler->display->display_options['row_options']['view_mode'] = 'teaser';
/* Relationship: Taxonomy term: Part Model (field_part_model) */
$handler->display->display_options['relationships']['field_part_model_tid']['id'] = 'field_part_model_tid';
$handler->display->display_options['relationships']['field_part_model_tid']['table'] = 'field_data_field_part_model';
$handler->display->display_options['relationships']['field_part_model_tid']['field'] = 'field_part_model_tid';
$handler->display->display_options['relationships']['field_part_model_tid']['label'] = 'Compatible Models';
$handler->display->display_options['relationships']['field_part_model_tid']['required'] = TRUE;
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = TRUE;
/* Contextual filter: Taxonomy term: Term ID */
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
$handler->display->display_options['arguments']['tid']['table'] = 'taxonomy_term_data';
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
$handler->display->display_options['arguments']['tid']['relationship'] = 'field_part_model_tid';
$handler->display->display_options['arguments']['tid']['default_action'] = 'not found';
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['tid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['tid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['tid']['summary_options']['items_per_page'] = '25';

/* Display: Related Parts */
$handler = $view->new_display('panel_pane', 'Related Parts', 'panel_pane_2');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Related Parts';
$handler->display->display_options['display_description'] = 'Finds a list of parts that are related to the currently-viewed model.';
$handler->display->display_options['argument_input'] = array(
  'tid' => array(
    'type' => 'context',
    'context' => 'entity:taxonomy_term.tid',
    'context_optional' => 0,
    'panel' => '0',
    'fixed' => '',
    'label' => 'Taxonomy term: Term ID',
  ),
);
  • I was about to ask this question, and then I found this post from last year! I'm still looking for a way to do this. – ouni Apr 6 '15 at 17:09
  • I was about to ask this question, and then I found this post from last year! I'm still looking for a way to do this. This should be a very simple query: for the currently-viewed taxonomy term, find all "part" terms that reference this term from the field parts_model. – ouni Apr 6 '15 at 17:14
  • The issue was due to Page Manager passing multiple tids to the exposed filter for some reason. I re-saved the page variant, and it works normally now. – ouni Apr 6 '15 at 19:03
1

In order to create a view that will display more relevant options to Taxonomy you have to choose taxonomy as your base table.

In drupal 7, when creating a view, select "Taxonomy Terms" under the "Show" drop-down. add your field for the part and then create a relationship to your other taxonomy vocabulary via the taxonomy reference field that you created earlier on.

You can now add the taxonomy term of the other vocabulary when the relationship is matched.

for example: View example view example output

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.