wp_set_object_terms not updating database without a die()

I have added custom taxonomy to media attachments. From the individual post page these are updating correctly, with some tweaks to get the column count updating correctly – and I can see these changes in the admin/database without a problem.

In the media popup, I can change the taxonomy and using the edit_attachment action I can see wp_set_object terms is firing, I can also see that it returns an array with the correct IDs in for the updated term:

wp_set_object_terms($id, $cat_ids, ‘attachment_category’, false);
//returns
array(1) {
[0]=>
string(1) “3”
}

3 being the correct ID for the term in question, however I cannot see an update in the database and when I refresh the page or close/reopen the popup the change is reverted.

Why is wp_set_object_terms in this case not updating the database but thinking it is successful? edit_attachment is the only action which correctly fired for me when the save-attachment-compat action is triggered on the form. If I add a die(); at the end of my function, and stop any further changes, it updates the database, is this the correct behaviour?

Read more here:: wp_set_object_terms not updating database without a die()

Leave a Reply

Your email address will not be published. Required fields are marked *