1

I have a content type, Job Offer, and this node type is able to expire thanks to Node Expire module.

When editing a Job Offer, I want to change the expire date by the value of the Duration field that I added to this node.

In order to do this, I made a rule with the help of Rules Module and I am using the custom PHP code below as an action in the light of this post, but it did not work with my field:

$node->expire = date('Y-m-d', strtotime("+[node:field-duration:field-value] days"));
return array("node" => $node);
  • node:field-duration:field-value is an integer field of a taxonomy term

Any help would be appreciated. Thanks

  • What happen when you use this instead of tokens. $duration = $node->duration[LANGUAGE_NONE]['value']; $node->expire = date('Y-m-d', strtotime("+" . $duration . " days")); return array("node" => $node); – undersound Feb 21 '17 at 23:25
  • It gave this eror: NPDOException: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'expire' at row 1: UPDATE {node_expire} SET expire=:db_update_placeholder_0, expired=:db_update_placeholder_1, lastnotify=:db_update_placeholder_2 WHERE (nid = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => -68400 [:db_update_placeholder_1] => 0 [:db_update_placeholder_2] => 0 [:db_condition_placeholder_0] => 110 ) in drupal_write_record() (line 7333 of /home/interjobcenter/public_html/drupal/includes/common.inc) – Xtrageik Feb 22 '17 at 9:15
  • But thanks I tried this one and it worked! $duration = [node:field-duration:field-value]; $node->expire = date('Y-m-d', strtotime("+" . $duration . " days")); return array("node" => $node); – Xtrageik Feb 22 '17 at 9:17
0

Thanks to @undersound, the code below worked!

$duration = [node:field-duration:field-value];
$node->expire = date('Y-m-d', strtotime("+" . $duration . " days"));
return array("node" => $node);
  • Sorry I'm questioning your answer here, but you do know that using PHP to create a Rules Action is something you should try to avoid whenever possible, right? Because it requires the dangerous PHP filter. Would you be interested in a Plan-B (again!) answer containing a blue-print (= suggestions for you to do some extra homework with other Rules facilities) to achieve the same result with rules that does not require any PHP? – Pierre.Vriens Mar 7 '17 at 11:51
  • It's ok. Sure I do. – Xtrageik Mar 7 '17 at 12:33

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.