How can I redirect a user after adding a node that also added a new taxonomy term? I have a content type with a Taxonomy for locations, these locations can be placed inside parent locations (f.ex United Kingdom -> England -> London), and it is set-up such that the end user can add taxonomy terms that do not currently exist when creating this content.

What I would like to achieve is upon creating a node that ALSO adds a NEW taxonomy term, is to redirect the page to the list of terms page so that the end user can categorise the new location appropriately.

Is this possible?
I'm not positive I understand the why, but the redirect-on-saving-new-node-with-new-terms bit should be reasonably straightforward.

I've suggested two possible methods below because the timing of db inserts/updates etc around node creation is a bit intricate, and you may need to shift the task to an earlier or later stage in the process. For example, the API docs mention that the db write cannot be presumed to be complete during hook_node_insert(), and it definitely won't be on hook_node_submit(). So your mileage may vary :)

You'll need to create a custom module (here's a stackexchange question on creating modules if you don't already know how) that either:


implements hook_node_submit()

This is the very likely to be the simpler/more reliable of the two methods.
implements hook_node_insert()

In this method, it is possible that drupal_goto() will conflict with the redirect specified in the node form's $form_state['redirect'], so it's probably the worse of the two possibilities.


Method 1: implement hook_node_submit()

From inside yourmodule_node_submit(), you'll need to:


Make sure that a node with this nid does not already exist!
find out what terms (if any) are in the new node ($node is passed into the function)
load all the terms for the relevant vocabulary, probably with taxonomy_vocabulary_load()
check to see if any of the node terms are not in the full list
modify $form_state['redirect'] if required


See drupal_redirect_form() for a bit more information on what happens with $form_state['redirect'].

Method 2: implement hook_node_insert()

From inside yourmodule_node_insert(), you'll need to:


find out what terms (if any) are in the new node ($node is passed into the function)
load all the terms for the relevant vocabulary, probably with taxonomy_vocabulary_load()
check to see if any of the node terms are not in the full list
if that's true, use drupal_goto() to redirect accordingly