Node reference using another field

Events happening in the community are now at Drupal community events on www.drupal.org.
Catalyst5's picture

Is it possible to use php to reference another node using a field inside this node?

The field contains the title of the other node - not the nid of the other node.

Comments

Nobody

Catalyst5's picture

Nobody knows how to do this?

Cmon guys

Catalyst5's picture

Any syntax help here please???

One way

itangalo's picture

There is an action 'Populate CCK field' that can be used for setting a node reference field. The problem here is that the field stores a node ID, not the title of the node (though often it is the title that is displayed).

You could do what you want in a fashion similar to this:

  • A view that takes a string as an argument, and returns all the nodes with that string as title. (This will be used to get the node ID when you have the title.)
  • The PHP filter module enabled (from core)
  • A suitable trigger for the rule
  • The action 'Populate a field'
  • PHP to set the field value. Here you will have to call the view created above, send something like [node:field_manually_entered_title] as argument, and fetch the results.

The most tricky part here is of course the last step. It is definately feasible, but before going down this track I recommend that you consider changing the architecture intestead. Could the textfield with node titles as strings be changed to a regular node reference field?

Good luck!
//Johan Falk, NodeOne, Sweden

Change architecture

Catalyst5's picture

Hi Itangalo

Thanks for your idea.Just to clarify - When you say "A view that takes a string as an argument" did you mean a rule set?

As for changing the architecture - No, I cannot change it, as the nodes are imported using an XML feed, so there is no way for me to reference one to another, even though I know the title / id / taxonomy of the other node :(

If you could expand on your idea that may work... I just don't understand how to do it

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: