Strictly by what I see in your code: you are trying to unset
incorrectly, unset
works by means of an array key and you are using $term_id
which is a value. You need to find the index in the array for that $term_id
:
function wpfs_save_tax( $term_id ) {
$featured_tax = get_option( '_featured_tax' );
if ( empty( $featured_tax ) ) {
$featured_tax = array();
}
if ( isset( $_POST['wpfs_tax'] ) ) {
if ( ! in_array( $term_id, $featured_tax ) ) {
$featured_tax[] = $term_id;
}
} else {
if ( in_array( $term_id, $featured_tax ) ) {
unset( $featured_tax[array_search( $term_id, $featured_tax )] );
}
}
update_option( '_featured_tax', $featured_tax );
}