Within an instance of hook_submit (for a custom form), I'm trying to iterate over a list of nodes, updating each of them. The general outline is

$x = node_load_multiple($nids);
$data = array(--some data--);

foreach ($data as $row) {
  $node = $x[$row['nid']];
  $node->field_some_field['und'][0]['value'] = $row['some_field'];

drupal_set_message('Nodes updated');

The problem I'm having is that rather than looping through the whole data array and then posting my confirmation message on the form page, Drupal updates the first node, exits the loop, and redirects to the user's home page with the message 'contenttype TITLE updated.'

Possibly relevant: I could have sworn this code block worked when the site was 7.2, but after updating to 7.23 I'm seeing this.

  • 4
    You've got something, somewhere, performing a redirect when nodes are created/updated. Maybe a rule? A custom module implementing hook_node_insert() or hook_node_update()?
    – Clive
    Commented Oct 8, 2013 at 22:19
  • Yep, that was it. Something I'd forgotten about in a hook_node_update... Thanks!
    – bricoleur
    Commented Oct 9, 2013 at 0:12
  • bricoleur If you could post what you found as an answer, it might be useful for someone in the future. @GisleHannemyr "too localized" was removed from close reasons for a reason, wasn't it?
    – Mołot
    Commented Oct 9, 2013 at 7:39

1 Answer 1


To summarize one of the comments, when you encounter weirdness with the API, you need to do two things.

First, look at the API call you are using, and see what hooks it invokes. Then, check your code for any hook implementations that could cause the weirdness. In this case node_save() invokes a few: hook_node_presave(), hook_entity_presave, hook_node_update, and hook_node_update for nodes that exist.

Second, you need to check any Rules that are attached to the the API call you are doing. In this case, you would check for rules that run when nodes are saved.

Doing these two things will usually lead you to the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.