plugin development - 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

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?

Share Improve this question asked Jun 12, 2019 at 10:41 AravonaAravona 5851 gold badge5 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Before 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

相关推荐

  • plugin development - 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

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信