最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - Prevent other hooks from firing after wp_update_post() outside of editor

programmeradmin2浏览0评论

I'm working on a plugin that batch updates post content using a call to wp_update_post(). This all happens outside the editor window, in a batch processing script. My problem is that ACF is firing after I run the wp_update_post() call as I think its because of the save_post hooks that run.

This is blanking all my ACF meta, as the values are not present in the post array at that point in time, so how can I prevent anything else firing on this call?

I've tried remove_all_actions('save_post') and remove_all_actions('acf/save_post') just before the call but its not having any effect.

$updated_post = array(
                    'ID' => $current_id,
                    'post_content' => $post_content,
                );
remove_all_actions('save_post');
$result = wp_update_post($updated_post, true);

Ideally I'd like to use a wordpress api function to update the content, as it will create a revision, whereas a direct SQL update will not.

发布评论

评论列表(0)

  1. 暂无评论