Support

Account

Home Forums Add-ons Repeater Field I need help populating repeater field with WP All Import Reply To: I need help populating repeater field with WP All Import

  • After reading tons of documentation I came up with this:

    add_action( 'pmxi_saved_post', 'soflyy_add_data', 10, 3 );
    
    function soflyy_add_data( $id, $xml, $update ) {
      $selector = 'car_make_model_year'; // Parent field name
      $subfield1 = 'car_make'; // The repeating field you want to add the first value to
      $subfield2 = 'car_model'; // The repeating field you want to add the second value to
      $subfield3 = 'car_year'; // The repeating field you want to add the third value to
      $subfield4 = 'car_type'; // The repeating field you want to add the forth value to
    
      if ( $value1 = get_post_meta( $id, 'my_repeater_data_car_make', true )) {
    	  $value2 = get_post_meta( $id, 'my_repeater_data_car_model', true );
    	  $value3 = get_post_meta( $id, 'my_repeater_data_car_year', true );
    	  $value4 = get_post_meta( $id, 'my_repeater_data_car_type', true );
        $row = array( $subfield1 => $value1, $subfield2 => $value2, $subfield3 => $value3, $subfield4 => $value4,  );
        add_row( $selector, $row, $id );
      }
    
      delete_post_meta( $id, 'my_repeater_data_car_make' );
      delete_post_meta( $id, 'my_repeater_data_car_model' );
      delete_post_meta( $id, 'my_repeater_data_car_year' );
      delete_post_meta( $id, 'my_repeater_data_car_type' );
    }

    and it looks like it works.
    I do not know if this the proper syntax or the best way to do it.