2

I read the documentation and saw that this is possible: node/add/page?field_bar=1,2,3

But how do you code this? I wanted to pass multiple target id, not just one.

I tried this code but this only passes 1 value which is the first field value.

<?php
$l = l( t('Create Package'), 'node/add/package',   array('query' => array('field_product_food' =>$node->field_product_food['und'][0]['target_id'])  ));
echo $l; 
?>

I also tried using an array loop like this:

<?php
$nids = array();
foreach ($node->field_product_food[$node->language] as $index => $item) {
$nids[] = $item['target_id'];
}
$l = l( t('Create Package'), 'node/add/package',   array('query' => array('field_product_food' =>$nids)  ));
echo $l; 
?>

but the result is not like the example from the documentation.

Can somebody help me?

Thank you very much!

2

So if you want to create this link: node/add/page?field_bar=1,2,3

You need to put a comma between each nid, so implode() is what you want.

E.g.

$l = l( t('Create Package'), 'node/add/package',   array('query' => array('field_product_food' => implode(',', $nids))  ));
1
  • OMG it worked! you're a life saver.. thank you my friend.. :D – Danz Apr 20 '15 at 6:24

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.