1

I have a content type - 'video post'. This content type has several taxonomy terms associated with it, 'star rating' and 'warm up'.

The 'star rating' taxonomy is a list of numbers: 1, 2, 3, 4

The 'warm up' taxonomy has 3 options: warm up, long, cool down.

What I've been trying to do is to create a view block to display on the content type 'video post' so that it displays a list of nodes which have the exact same set of taxonomy terms as the one currently being viewed.

So if I go to node/1 and this has these two taxonomies as follows:

star rating - 2

warm up - long

I only want nodes to display which also have this same combination of terms.

It would also be great if I could exclude the current node from the list too, as this is obviously not required.

I've tried just about everything that I know, but I always seem to get results that I don't want.

Any help is greatly appreciated.

0

Download the Views PHP module:

This module allows the admin account (user 1) to add fields, filters and sorts to views which use PHP code. It also supports additional accounts when the core PHP Filter module is enabled.

In Views:

  • create a new View of 'video post' content type, as a block and set it up to show all entries for now, in the format and layout you desire

  • add a contextual filter for the star rating field (you will need to adjust the field names appropriately):

    • Provide a default value, PHP code:

      $node = menu_get_object();
      return $node->field_star_rating['und'][0]['tid'];
      
  • add another contextual filter for the warm up field:

    • Provide a default value, PHP code:

      $node = menu_get_object();
      return $node->field_warm_up['und'][0]['tid'];
      

The first line retrieves the page object (which should only ever be a video post node if the block is set up properly), then returns the term ID associated to the current node as a contextual filter to the view. This assumes a single language site.

  • add a regular filter, Global PHP code:

    $node = menu_get_object();
    if($data->nid == $node->nid) return true;
    else return false;
    

The first line again retrieves the page object, and compares its node ID with the node ID of the current entry, filtering it if they match. It may appear backwards, but that's how the Global PHP works for some reason. Returning true excludes the row.

  • under admin/structure/block, set the view-block to show where you want on the page, restrict it to show only on the content type video post.
8
  • Thanks for taking the time. Is the 1st item: Content: Stars rating (field_stars_rating) in contextual filters and what do I choose for the regular Global filter - I don't know where to find that one? – njwrigley May 4 '15 at 19:06
  • if that is what your field is called yes - without knowing the machine names you used, I guessed. Global PHP is the regular filter – Geoff May 4 '15 at 19:09
  • I should be more clear - using the GUI of views, how do I locate the regular filter, Global. Is this a contextual filter, or just a filter under 'filter criteria'? – njwrigley May 4 '15 at 19:10
  • In Global, under 'Filter Criteria', I have options for Global: Combine fields filter and Global: Fields comparison – njwrigley May 4 '15 at 19:11
  • oops, I think you need the Views PHP module - try that, if it shows up I will edit my answer – Geoff May 4 '15 at 19:14

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.