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}");
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.