Support

Account

Home Forums Add-ons Repeater Field if have_rows() fails in acf/save_post

Unread

if have_rows() fails in acf/save_post

  • Hello,

    I’m trying to copy the data in repeater fields while saving. It works when priority is low (1), but that gives the old values. When priority is high (20), it doesn’t get past if (have_rows()) (which returns “”). It does work correctly when called from elsewhere (i.e., not during acf/save_post).

    Any idea why or how to fix? Thank you very much for any help!

    function motw_acf_save_post() {
    	$screen = get_current_screen() ;
    	if ( strpos( $screen->id, "acf-options-motw" ) == true ) {
    		$list = get_option( 'motw_list' ) ;
    		if ( have_rows( 'motw_repeater', 'options' ) ) {
    			while ( have_rows( 'motw_repeater', 'options' ) ) {    
    				the_row();
    				$list[ get_sub_field( 'motw_date' ) ] = get_sub_field( 'motw_name' )[ 0 ]->post_title ;
    			}
    			ksort( $list, SORT_NUMERIC ) ;
    			update_option( 'motw_list', $list, false ) ;
    		}
    	}
    }
    add_action( 'acf/save_post', 'motw_acf_save_post', 20 ) ;
Viewing 1 post (of 1 total)

The topic ‘if have_rows() fails in acf/save_post’ is closed to new replies.