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

theme development - Running a function on post update with new post meta

programmeradmin0浏览0评论

I am trying to run a function on post update by checking if an ACF is equal to something.

I'm checking if the ACF value is equal to new or closed.

when i change it from value new to closed and save it doesn't run but if i save the post again when the post is at closed it does run.

function check_values($post_ID){
    if(get_field('status', $post_ID ) == "closed") {
        sendSMS();
    }
}

add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function

Is there something I'm missing about this? I want to avoid saving each post twice.

Thank you

I am trying to run a function on post update by checking if an ACF is equal to something.

I'm checking if the ACF value is equal to new or closed.

when i change it from value new to closed and save it doesn't run but if i save the post again when the post is at closed it does run.

function check_values($post_ID){
    if(get_field('status', $post_ID ) == "closed") {
        sendSMS();
    }
}

add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function

Is there something I'm missing about this? I want to avoid saving each post twice.

Thank you

Share Improve this question edited Mar 9, 2020 at 6:30 sleepingpanda 566 bronze badges asked Mar 8, 2020 at 13:27 Asaf HadadAsaf Hadad 357 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Please try using acf/save_post action that will hook in after ACF data has been saved.

add_action('acf/save_post', 'check_values');

function check_values($post_id){
    if(get_field('status', $post_id ) == "closed") {
        sendSMS();
    }
}
发布评论

评论列表(0)

  1. 暂无评论