Home Forums Add-ons Repeater Field Update sub field before/after save post Reply To: Update sub field before/after save post

  • Looking back over your comment, to be honest I’m not sure where the problem is. However, if I was going to update a field associated with ACF and I needed to look at old values vs new values

    add_action('acf/save_post', 'update_post', 1);

    Setting the priority of 1 means that your function will run before ACF saves the new values. This means that you can use the ACF functions have_rows() and get_sub_field() to get the old values and $_POST['acf'] for the new values.

    In your OP you indicated that you tried this

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

    This sets the priority to 10, which is the same as when ACF runs it’s save. There isn’t any way to guarantee under this condition which will run first, your function or ACF.

    Looking at your last comment, you need to supply the post ID for the initial have_rows() calls in your filter so that ACF knows what post to look at.

    function update_post( $post_id ) {
        $projectCount = -1;
    	if( have_rows('project', $post_id) ):
    		while( have_rows('project', $post_id) ): the_row();
    // after this you don't need to add $post_id for any sub fields

    Hope that helps