Detecting when a custom taxonomy has been changed and display alert?

I’m building a plugin with a CPT and custom taxonomy – location. Everything’s been working fine except I need to add a dismissible admin alert when the custom taxonomy has been changed either from the quick edit box or the post edit page. For the life of me I can’t figure out how to do this.

I’ve got a sketch for the alert.

<?php function my_update_location_alert() { ?>
  <div class="notice notice-warning is-dismissible">
    <p><?php /*message about the changed taxonomy...*/ ?></p>
  </div>
<?php
}
add_action('admin_notices', 'update_location_alert');

But, I’m struggling to understand how to detect the change to the taxonomy and what hooks are appropriate. Perhaps something like –

function my_change_location() {
  global $post;
  $post_ID = $post->ID;
  $location = wp_get_post_terms($post_ID, 'location');
  if ($post->post_type === 'request_form') {
    /* this is where I get stuck. */
  }
}

Thanks for any help you can offer!

1 Answer
1

You need to:

  1. Hook into the edited_$taxonomy action. Just replace $taxonomy with the name of your custom taxonomy. Based on your example I think edited_location will work for you.

  2. Create a custom query_var to pass on the fact that your taxonomy has changed.

For #2, this answer should get you going. Good luck!

Leave a Comment