What hooks/filters are there to alter selected terms on post save?

It is always 'save_post' (or 'wp_insert_post' immediately after this). In $_POST['tax_input'] you will find all the terms for all taxonomies associated with the current post.

Example:

'tax_input' => 
  array (
    'location' => 
    array (
      0 => '0',
    ),
  ),

To change the terms you have to call wp_set_post_terms( $post_ID, $tags, $taxonomy ); manually, just changing these values will not work because they are set when the actions fire.

For an existing post that is updated you can hook into 'edit_post' and 'post_updated'.

Parameters for all these actions are $post_ID, $post in this order. For 'post_updated' there is a small change: $post_ID, $post_after, $post_before.

Leave a Comment