Support

Account

Home Forums Add-ons Flexible Content Field Get value from Flexible Content field outside the loop Reply To: Get value from Flexible Content field 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

    
    "{$flex_field_name}_{$row_index}_{$sub_field_name}"
    

    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;
        break;
      }
    }
    

    then you can get the field

    
    if ($found) {
      $value = get_field("{$flex_field_name}_{$row_index}_{$sub_field_name}");
    }