Populating a node reference field using PHP in Rules I have a rule which is triggered when a node is flagged. Currently, the rule loads some content (1) that has been referenced by a field on the flagged content. I have set the rule to create a new piece of content (2) and would like a node reference field on this new piece of content to reference content (1). I know there is a way to do this with PHP but am not sure of it...

Got one more...

I'm now trying to use rules to populate a select list field on a new piece of content. I need the value of the field to be the same as a piece of referenced content that's available to rules. Usually I would use tokens but as its a select list field there is nowhere for me to insert a token. I'm thinking some PHP would do the job, but I don't know where to start.
This should actually be pretty simple:


Create your rule for the event "A node has been flagged, under "NAME OF YOUR FLAG" and name your rule
Add an action of "Add new content" and click "Next"
Choose what you want the auto-created content's title to be (w/ or w/out tokens) and select what content type you want created and click "Save"
Add another action of "Populate a field", for the arguments configurations choose "new content type of CONTENT TYPE YOU CREATED" and for field, choose your node reference field and click "Continue"
Again on arguments change to "new content type of CONTENT TYPE YOU CREATED"
Open the fieldset titled: "Advanced: Specify the fields value with PHP code" and enter:


return array(0 =&gt; array('nid' =&gt; $node-&gt;field_NAMEOFYOURFIELD[0]['nid']));

Note: You can find the field names by going to admin/content/types and click "Manage Fields" on the content type you want OR you can do a print_r($node); on a node of that content type to see the node object structure

Now when you view your rule, you should see something like:



and whenever you use that flag, a new node will be created having the same reference as the node you flagged.