PROBLEM
In views for D7 nodes returned have to have all terms in common with the node being viewed instead of just one in common, like in views for D6.

EXPLANATION
In D6 I had a view with the arg NID from the URL and Taxonomy: Term ID from PHP Code

http://awesomescreenshot.com/0d39j5q17
http://awesomescreenshot.com/01e9j5rb2
http://awesomescreenshot.com/01b9j5u7f

$node = node_load(arg(1));
if($node){
foreach($node->taxonomy as $term) {$terms[] = $term->tid; }
return implode('+', $terms);
} else { return; }

This view displays nodes that are tagged with at least one similar taxonomy term as the node currently being viewed.

For this explanation I have four nodes with the following terms associated
Node1: White, Blue
Node2: Purple
Node3: White, Red
Node4: Yellow

TESTING
In D6 if the node has the terms (White, Purple) then nodes 1,2,3 would be displayed.
In D7 if the node has the terms (White, Purple) then no nodes would be displayed.
In D6 if the node has the terms (White, Red) then nodes 1,3 would be displayed.
In D7 if the node has the terms (White, Red) then node 3 would be displayed.

CONCLUSION
In D7 the PHP snippet no longer works. I've looked at the new option to supply the default argument "Taxonomy Term ID from URL" but I've had limited success as you can see.
http://awesomescreenshot.com/0d99j5fb3

YOUR HELP NEEDED
Any advice on how to convert over this PHP snippet or how to achieve this functionality in views for D7 would be greatly appreciated.

Comments

bryancasler’s picture

Someone in IRC pointed out that $node->taxonomy is gone. I tried substitution in my field name $node->field_tags but that did not work.

bryancasler’s picture

I've made a little progress, but not there yet.

$node = node_load(arg(1));
if($node){
foreach($node->field_tags['und'] as $foo) {$foo['tid'] = $term->tid; }
return implode('+', $foo);
} else { return; }
bryancasler’s picture

I noticed a conversation happening here #684608: Default Argument for taxonomy tids that would be a solution, but it's for D6

dawehner’s picture

$node = node_load(arg(1));
if($node){
foreach (field_get_items('node', $node, 'field_tags') as $term ) {
  $terms[] = $term['tid'];
}
return implode('+', $terms);
} else { return; }
bryancasler’s picture

Thank you so much dereine. I just found another way to achieve this with panels. Below is my walk through.

First apply this patch to views. http://drupal.org/node/1081118

Create your view
Add the argument/contextual filter "Taxonomy: Term ID"
Choose Provide default value > Taxonomy Term ID from URL
Check Load default filter from term page
Under "Multiple arguments type" choose 1+2+3 (for OR) *This is what is provided by the patch

You may also want to exclude the node that's currently being viewed from showing up in the list. To do that add another argument/contextual filter "Content: NID" or "Node: NID"
Then choose Provide default value and "Content ID from URL" or "Node ID from URL"
At the bottom make sure to check the "Exclude" box

Add your view to your panel
Now that you have your view setup add a content pane.
Then go to the panes "Argument input"
From "Taxonomy: Term ID source" choose "From context"
From "Required context" choose "Term ID" under the Taxonomy term heading
You might also want to check the "Context is optional" box

Now go to your panel and add the following contexts.
*My taxonomy field is name "field_tags", choose the appropriate context
Add "Taxonomy term from Node on field_tags field"

Now add your content pane to your panel.
In your content pane's settings choose "Taxonomy term from Node on field_tags field"

Finish
Save your panel and now everything should work!

merlinofchaos’s picture

Status: Active » Fixed
bryancasler’s picture

I posted a longer follow up here for anyone who stumbles on this #1111384: How to create a panel with related content based on multiple terms.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.