Hi Drupal folks!

Please bear with my explanation, I'll try to make it easy to follow.

I'm hoping this is easy, but I'm looking for a way to display some fields within a block IF content in a field of the node matches the content in a field for a different node of a different Content Type.

In case that sounds confusing, here's an example. Let's say we have Content Types "Fruit" and "Vegetable", and within each Content Type we have a field "Color".

Now let's say I have a node within Fruit called "Granny Smith Apple" and it's Color field says "Green". In the "Vegetable" Content Type I have a node "Celery" and it's "Color" field also says "Green."

So when someone is looking at the "Granny Smith Apple" node, I want a block to show "Celery, Green". Formatting doesn't really matter (i.e. comma vs hyphen for example) but I want the information there. If there is more than one match, then I'd want both to show. For example, both "Celery, Green" and "Lettuce, Green" might appear.

Any easy PHP code to make that happen?

Thanks!

Comments

Much easier if you use vocabularies and term reference fields.

How can it be done with fields? The system is in place, this is something that has presented itself as a need.

The ability to do this would be very beneficial, so I'd really be thankful for any assistance.

As nevets mentioned, this is typically done with taxonomy terms (so most of the googable results will describe how to do it with taxonomy), but you should be able to do it with other fields as well. Create a block view, add an argument for the field you want to use as a filter (ie 'field_color'), select the 'provide default value' option, then 'php code' and use something like the following (totally untested):

<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
 
$node = node_load(arg(1));
  if (!empty(
$node->field_color[0]['value'])) {
    return
$node->field_color[0]['value'];
  }
  else {
    return
FALSE;
  }
}
?>

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.