Home Forums Add-ons Repeater Field acf/input/form_data conflicting with DB query Reply To: acf/input/form_data conflicting with DB query

  • You’re Brilliant @hube2! This fixed it!

    Here is a simplified version of how the code worked:

    function update_sub_fields() {
      global $wpdb; //declare using a global variable
      $import_post_id = get_field('import_post'); //get the id of the post we are importing data from
      if( have_rows('repeater_field_name') ):  //start the repeater loop
         while( have_rows('repeater_field_name') ): the_row();
             $unique_id = get_sub_field('unique_id_field'); //get the unique id
             $rows = $wpdb->get_results($wpdb->prepare( 
    		SELECT * 
    		FROM {$wpdb->prefix}postmeta
    		WHERE post_id = %s
    		AND meta_key LIKE %s
    		AND meta_value = %s
    		$import_post_id, //only look at meta-values that match the post we are importing from
    		'import_repeater_field_%_unique_id_field', // meta_name: $ParentName_$RowNumber_$ChildName
    		$unique_id // meta_value: to match our unique id
    	if( $rows ){
    	   foreach( $rows as $row ){
    		preg_match('_([0-9]+)_', $row->meta_key, $matches);
    		$r = $matches[0]; 
    	        $import_rows = get_field('import_repeater_field', $import_post_id);
    		$current_import_row = $import_rows[$r];
                    $sub_field_to_import = $current_import_row['sub_field_to_import'];
                    update_sub_field('new_field_to_update', $sub_field_to_import);
                } //End foreach
              } //End if
            endwhile; //end loop
    add_action( 'acf/imput/form_data', 'update_sub_fields', 10, 1);

    I hope this helps anyone else who might be looking to import data from one repeater field to another!