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?
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?
1 Answer
Reset to default 0Before using $cat_ids
in the wp_set_object_terms()
function, cast all values from the string to a number.
Note from the documentation:
Integers are interpreted as tag IDs. Warning: some functions may return
term_ids
as strings which will be interpreted as slugs consisting of numeric characters!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745410895a4626528.html
评论列表(0条)