Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Very simple, where would I hook/filter to alter the users selection of terms when they save a post (Update or Add)?

I need to hook in all instances; such as when saving a post via AJAX, saving when JavaScript is disabled and a normal POST is done and when posts are saved via quick edit.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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