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

  • Hey all,

    I can’t seem to get the solution from @bigdropgr to work. I have an CSV with four columns (store, name, scm, points), a repeater named ‘leaderboard’ with subfields named ‘store’, ‘name’, ‘scm’ and ‘points’. I set up dummy custom fields as suggested by @bigdropgr and mapped them to the fields in the CSV (screenshot). Then I pasted this into the function editor:

    <?php 
    
    add_action( 'pmxi_saved_post', 'soflyy_add_data', 10, 3 );
    
    function soflyy_add_data( $id, $xml, $update ) {
      $selector = 'leaderboard'; // Parent field name
      $subfield1 = 'store'; // The repeating field you want to add the first value to
      $subfield2 = 'name'; // The repeating field you want to add the second value to
      $subfield3 = 'scm'; // The repeating field you want to add the third value to
      $subfield4 = 'points'; // The repeating field you want to add the forth value to
    
      if ( $value1 = get_post_meta( $id, 'my_repeater_data_store', true )) {
    	$value2 = get_post_meta( $id, 'my_repeater_data_name', true );
    	$value3 = get_post_meta( $id, 'my_repeater_data_scm', true );
    	$value4 = get_post_meta( $id, 'my_repeater_data_points', true );
        $row = array( $subfield1 => $value1, $subfield2 => $value2, $subfield3 => $value3, $subfield4 => $value4 );
        add_row( $selector, $row, $id );
      }
    
      delete_post_meta( $id, 'my_repeater_data_store' );
      delete_post_meta( $id, 'my_repeater_data_name' );
      delete_post_meta( $id, 'my_repeater_data_scm' );
      delete_post_meta( $id, 'my_repeater_data_points' );
    }
    ?>

    I am using the Advanced Custom Fields Add-on, but from what I understand, I don’t need to set anything here since it’s being handled in the Custom Fields area. In the settings area, I’m just updating the ‘leadership’ custom field (screenshot). Ideally, these fields will populate a repeater on a Page. Can anyone point me in the right direction here? Any help would be appreciated. Thanks!

    Also including this snippet from the import log, as it may be helpful.

    [03:53:16] UPDATINGLeaderboardPage`
    [03:53:16] Associate post Leaderboard with current import …
    [03:53:16] CUSTOM FIELDS:
    [03:53:16] ACF ADD-ON:
    [03:53:16] – Custom field my_repeater_data_store is not set to be updated in import settings, skipping …
    [03:53:16] – Custom field my_repeater_data_name is not set to be updated in import settings, skipping …
    [03:53:16] – Custom field my_repeater_data_scm is not set to be updated in import settings, skipping …
    [03:53:16] – Custom field my_repeater_data_points is not set to be updated in import settings, skipping …
    [03:53:16] IMAGES:
    [03:53:16] UPDATED Leaderboard Page (ID: 17)
    [03:53:16] ACTION: pmxi_saved_post
    [03:53:16] ACTION: pmxi_after_post_import
    [03:53:16] —`