Creating new ACF Repeater rows from import

bernard

BuSo Pro
Joined
Dec 31, 2016
Messages
2,599
Likes
2,302
Degree
6
I'm not too pleased to discover, after spending for ACF Pro, that you can't import and create a new row to a repeater field from WP All Import. You can only overwrite.

I'm using it to store prices for dates, so that I can chart it with Chart.js (works fine), so each import should have created a new row of Date/Price, not overwrite with the current Date/Price.

Question is what to do?

I'm thinking it has to be using add_row (https://www.advancedcustomfields.com/resources/add_row/), function of ACF to create a function that grabs prices imported into "current price" and then combine with date in these new rows. Then have a WP All Import hook call than function following import?

I don't know if it works, but that sounds workable?
 
@bernard, I got curious because I used to use WP All Import about a decade ago. Made some good money with it. It's changed so much. They have a million hooks too, so many that I couldn't read them all, but thankfully I stumbled upon:

1) pmxi_acf_custom_field and 2) pmxi_saved_post.

I'm not saying I have any answer here for you, but I'm sharing what I found, hoping it can be a lead toward the right answer for you.

Here's a code snipped in the documentation for Append ACF Repeater Data. It says you have to use an Existing Items Import since the ACF post already exists. If you click the link, it shows how to set it up to only update the custom fields with the exact name you want, while updating nothing else.

They do use add_row() here too along with pmxi_saved_post(). In this example (which is the same behind the link above), they have a repeater called basic_repeater and the sub-field called repeater_text.

PHP:
add_action( 'pmxi_saved_post', 'soflyy_add_data', 10, 3 );
function soflyy_add_data( $id, $xml, $update ) {
    // Parent field name.
    $selector = 'basic_repeater';
    // The field to be appended.
    $subfield1 = 'repeater_text';
    // Only continue if my_repeater_data contains a value.
    if ( $value = get_post_meta( $id, 'my_repeater_data', true ) ) {
        // Format data for repeater.
        $row = array( $subfield1 => $value );
        // Add new repeater row.
        add_row( $selector, $row, $id );
    }
    delete_post_meta( $id, 'my_repeater_data' );
}

I guess that function gets looped for every row of data by WP All Import. If not, you should be able to make it loop somehow for bulk imports. If you're doing daily imports then this looks like it would get the job done. I'm too unfamiliar with it now to really know the ins and outs. Seems powerful though. I made and sold a few database sites many moons ago with it.
 
Yes, that worked perfectly, don't need to run a second import, it will trigger simply by running every import.
 
Back