I am trying to figure out why wp_set_object terms will update the terms in a given taxonomy but when I set the $terms param to NULL it keeps one of the terms - the one with the lowest ID.
I've altered a plugin for frontend editing of posts - WP User FrontEnd.
Here's my wp_set_object_terms code coming from a set of check boxes in a form:
if( !empty($_POST['wpuf_tax_TAXONOMY']) ):
$cat_ids = $_POST['wpuf_tax_TAXONOMY'];
$cat_ids = array_map('intval', $cat_ids);
$cat_ids = array_unique( $cat_ids );
wp_set_object_terms( $post_id, $cat_ids, 'TAXONOMY' );
else:
wp_set_object_terms( $post_id, NULL, 'TAXONOMY' );
endif;
Not sure what to do about this or why it won't delete the terms when none are selected in the form.
Any help is appreciated.
EDIT---------------------------------------------------------------
I have noticed that wp_set_object_terms does add and remove terms as expected. But I need to refresh the page after the form update to see the changes.
I tried a wp_redirect on successful submission but got a "headers already sent" error. Is there a way to reload the page with out having to refresh the page after the from updates? Hope that made sense.