Home Forums Add-ons Flexible Content Field Get value from Flexible Content field outside the loop


Get value from Flexible Content field outside the loop

  • Hello! I will be very grateful for the help.

    I have Flexible content field with sub field where I dynamically populate form id for Gravity form, like this. In the loop from documentation for ACF I successfully get my id.

    But I need put somehow this ID in Gravity code for display form on the page. Earlier I use code like this

    gravity_form(get_field('contact_us_form_id', 'option'), true, false, false, '', false); ?>

    where ‘contact_us_form_id’ – field name. ‘option’ – field group name

    and it’s works.

    But what I must write instead (‘contact_us_form_id’, ‘option’) if I have flexible content field with subfield (Field group name + name of flexible content field + name of layout + name of sub field). Value not passed outside the loop

  • It would be extremely difficult to get this value outside of the loop and outside of the flex field loop.

    You would need to know the row index of the flex field layout. The meta key for the field is


    A possibility would be to use

    $layouts = get_post_meta($post_id, $flex_field_name, true)

    This will return an array of flex field layouts

    array('row_0_layout_name', 'row_1_layout_name', 'row_2_layout_name'/* etc */)

    you can then loop over this array to find the correct layout.

    $found = false;
    foreach ($layouts as $row_index => $layout) {
      if ($layout == 'the layout your looking for') {
        $found = true;

    then you can get the field

    if ($found) {
      $value = get_field("{$flex_field_name}_{$row_index}_{$sub_field_name}");
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.