Support

Account

Home Forums Backend Issues (wp-admin) Multisite Repeater update_field issues

Solved

Multisite Repeater update_field issues

    • klivie

    • October 8, 2020 at 9:34 pm

    Hi all,

    I’m having some difficulty using the update_field() function alongside repeater data.

    We’ve got some code in our multisite at the moment so when you publish a post it will also post it on the sub sites as well as copying across all the meta data.

    The example we’ve followed is here: https://rudrastyh.com/wordpress-multisite/post-to-all-sites.html

    This is working pretty well. It posts across multisites without any issues so far but we cannot get the repeater data copying across at all.

    We’ve been using this thread (https://support.advancedcustomfields.com/forums/topic/repeater-update_field/) for guidance but it doesn’t seem to work.

    It seems to create the correct number of rows within our repeater (e.g. 3 rows using example below) but the actual sub field data is just left blank. e.g. the URLs don’t save in the sub fields.

    a var_export() of my repeater data gives me this:

    array (
      0 => 
      array (
        'field_5df8e6a37e4c1' => 'http://google.com/',
      ),
      1 => 
      array (
        'field_5df8e6a37e4c1' => 'https://www.bbc.co.uk/news',
      ),
      2 => 
      array (
        'field_5df8e6a37e4c1' => 'https://www.facebook.com/',
      ),
    )

    We then do:

    update_field('field_5df8e6987e4c0', $repeater_values, $inserted_post_id);

    So field_5df8e6987e4c0 is the meta key of the repeater field, field_5df8e6a37e4c1 is the meta key of our sub field. Both of these are the keys from the TARGET site. Not the CURRENT site.

  • The issue probably comes down to the fields not existing on the site you are publishing from. The fields need to exist on both sites with the same keys, even if they are not used.

    ACF loads field groups during ‘init’, so it only knows about the field groups for the current site. When you switch to another blog to add the post ACF does not then look for fields for that other blog and does not find the key.

    • klivie

    • October 9, 2020 at 12:10 am

    Hi John,

    Thanks for the speedy response.

    The field groups do already exist on the site I am publishing from. Although they do have different field keys.

    The repeater field key is field_5d14dda3d0dcc.
    The repeater sub field key is field_5d14ddb4d0dcd.

    Do these keys need to be the same across the multisites?

    The way we’re building our repeater array is shown here:

    
    //this is done before we use switch_to_blog()
    $downloads = get_field('downloads', $original_post->ID, false) 
    $repeater_values = [];
    foreach ($downloads as $download) {
         $repeater_values[]['field_5df8e6a37e4c1'] = $download['field_5d14ddb4d0dcd']; //meta key of the sub field. first key is the target site, second key is current site.
    }
    
    • klivie

    • October 9, 2020 at 12:19 am

    Sorry ignore the stray “)” within the foreach loop. Was just a typo.

    Note: I removed this using the “edit button” so ignore this comment.

  • Yes, the field keys need to be the same and the field types need to be the same across sites.

    The reason that I know this is that I’ve had this issue myself, not with using update field, but with getting field values, but they are related. I had a field group on sub sites I was trying to get data from to show on the main site that did not work. The field group did not exist on the main site. I added the group to the main site set and everything started to work.

    • klivie

    • October 15, 2020 at 9:28 pm

    Changing the field keys to be the same across all sites resolved the issue.

    Thanks for the help John.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.