Support

Account

Home Forums Add-ons Flexible Content Field Can't use add_row for a flexible content row within a repeater field

Solving

Can't use add_row for a flexible content row within a repeater field

  • Hi,
    Added this as a support ticket too.

    We’re using ACF Pro on the front end of a website. Rather than use ACF’s add_form, we’re creating our own UI.

    We’re having trouble adding a flexible content row within a repeater field. We use buttons to create each layout, that are already created in ACF. When we click a button we can create the first row using the following:

    $selector = 'repeater_0_flexible';
    $fieldKey = 'field_5039a99716d1d';
    $field = get_field($selector);
    $field[] = 'layout1';
    update_field( $selector, $field, $post_id );
    update_post_meta($post_id, '_'.$selector, $fieldKey);

    This appears to function perfectly and in the db we see a:1:{i:0;s:7:”layout1″;} for the post_meta for the meta_key ‘repeater_0_flexible’.

    However, when we try to add a second flexible content layout we’re having issues. Currently we’re trying:

    $field = get_field($selector); // this returns null for some reason??
    $field[] = array('acf_fc_layout' => $acfLayout);
    add_row( $selector, $field, $post_id );

    The result is that the data gets corrupted and both flexible fields disappear. We now see 2 as the post_meta for the meta_key ‘repeater_0_flexible’. get_field() at this point returns null for some reason.

    Any thoughts on what we can try?

  • Thank you for your quick reply but that referred to adding a brand new layout.

    I’m not sure if I explained it correctly, but what we’re trying to do is add a layout that already exists on the back end. We’re not trying to add a brand new layout on the front end. So, layout 1 and layout 2 already have been created in ACF manually.

    We want to be able to then add instances of these flexible content fields from the front end, but currently we can only get it to add 1 instance. Our code isn’t correct for adding more than 1, but the documentation for add_row doesn’t seem to help us when within a repeater field.

    Would appreciate any other ideas.

  • I’m sorry, it appears you got a reply to a comment I made on another post last night, which is odd.

    I’m not too sure about this one, have you tried using the field key when attempting to add the row instead of the field name?

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

The topic ‘Can't use add_row for a flexible content row within a repeater field’ is closed to new replies.