Php 高级自定义字段:保存帖子前更新子字段

Php 高级自定义字段:保存帖子前更新子字段,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,预期行为: 当用户在WP仪表板中更新ACF并点击更新时,代码将检查更新的状态字段,如果值已更改,还将修改上次更新的字段,然后保存所有信息 现实: 整体内容已更新,但上次更新的字段不受更新子字段代码的影响。但是,如果我删除末尾的return$post行,则会保存上次更新的字段,但总体内容会恢复为原始值(未保存) 我需要两个都被拯救!我有一种感觉,事情并没有按照正确的顺序发生,如果我能找到合适的过滤器/操作来运行,我可以做到这一点,但到目前为止,这些都没有与下面的代码一起工作(也尝试了不同的优先级作

预期行为:

当用户在WP仪表板中更新ACF并点击更新时,代码将检查更新的状态字段,如果值已更改,还将修改上次更新的字段,然后保存所有信息

现实:

整体内容已更新,但上次更新的
字段不受更新子字段代码的影响。但是,如果我删除末尾的return$post行,则会保存上次更新的字段,但总体内容会恢复为原始值(未保存)

我需要两个都被拯救!我有一种感觉,事情并没有按照正确的顺序发生,如果我能找到合适的过滤器/操作来运行,我可以做到这一点,但到目前为止,这些都没有与下面的代码一起工作(也尝试了不同的优先级作为参数):

非常感谢您的帮助。谢谢大家!

function update_post( $post ) {

$projectCount = -1;

if( have_rows('project') ):

    while( have_rows('project') ): the_row();

        $taskCount = -1;
        $projectCount++;

        if( have_rows('project_issue') ):

            while( have_rows('project_issue') ): the_row();

                $taskCount++;

                $oldValue   = get_sub_field('project_current_status');

                $newValue   = $_POST['acf']['field_594afbf65e909'][$projectCount]['field_594afd675e90d'][$taskCount]['field_594c05c666a9f'];

                $date = date('Ymd');

                $updated = ($oldValue !== $newValue) ? 'true' : 'false';

                if ( $updated == 'true' ) { 

                    update_sub_field('project_last_update', $date);

                }

            endwhile;

        endif;

    endwhile;

endif;

return $post;
}
function update_post( $post ) {

$projectCount = -1;

if( have_rows('project') ):

    while( have_rows('project') ): the_row();

        $taskCount = -1;
        $projectCount++;

        if( have_rows('project_issue') ):

            while( have_rows('project_issue') ): the_row();

                $taskCount++;

                $oldValue   = get_sub_field('project_current_status');

                $newValue   = $_POST['acf']['field_594afbf65e909'][$projectCount]['field_594afd675e90d'][$taskCount]['field_594c05c666a9f'];

                $date = date('Ymd');

                $updated = ($oldValue !== $newValue) ? 'true' : 'false';

                if ( $updated == 'true' ) { 

                    update_sub_field('project_last_update', $date);

                }

            endwhile;

        endif;

    endwhile;

endif;

return $post;
}