Support

Account

Home Forums ACF PRO How to assign value for a specific repeater sub field of sub field

Solving

How to assign value for a specific repeater sub field of sub field

  • Hi,
    Am trying to assign the value for my specific repeater sub field of sub field. But the values assigned with wrong meta key.

    Ex:
    Assigned value for the key:
    alternate_contacts_0_facebook

    Instead of,
    co-author_information_0_contact_information_0_alternate_contacts_0_facebook

    How to assign the sub field of sub field values by custom code ?

    Can you please help me out to assign the values for the specific sub field ?

  • Look at the last code example on this page

    https://www.advancedcustomfields.com/resources/update_sub_field/

    However, I would use field keys and not field names, especially if you are inserting a new value and not updating and existing value. In your case it might look something like this

    
    update_sub_field(
      array(
        'field_0123456789', 1, // field key for "co-author_information" repeater row 1
        'field_1234567890', 1, // field key for "contact_information" row 1
        'field_2345678901', 1, // field key for "alternate_contacts" row 1
        'field_3456789012' // field key for "facebook"
      ),
      'This value is for repeater row 1, and sub_repeater row 1, sub_sub_repeater row 1!' );
    
  • This reply has been marked as private.
  • I have a hierarchical based repeater fields for a specific custom post.

    I need to assign the values for the corresponding fields which is mentioned in the previous thread.

    I would like to push the data for the above hierarchical with multi rows. Can you help me out ?

  • You can also use update field to update the entire repeater all at once. For example

    
    $value = array(
      // create a nested array for each row of the repeater
      'field_0123456789' => array(
        // this is a nested repeater
        // again, create a nested array for each row
        'field_1234567890' => array(
          // nested nested repeater
          // you can do this indefinitely
          'field_9840329403284' => 'value of field',
          'field_9840329403284' => 'value of field',
        )
      ) // end for nested repeater array
    ); // end of repeater array
    

    Create some values in a repeater and save them. On the front end of your site do this

    
    echo '<pre>'; print_r(get_field('top_level_repeater')); echo '</pre>';
    

    you can use update_field() https://www.advancedcustomfields.com/resources/update_field/ to push the entire content of the repeater by using the same format for the array value as what the above code will display.

    If you are created values where none already exist then you need to replace the field names in the array that is output with the field keys for those fields. And Like I’ve said previously, it is always a good idea to be in the habit or using field keys when using any of ACF’s update functions.

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

The topic ‘How to assign value for a specific repeater sub field of sub field’ is closed to new replies.