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
<?php
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
"{$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}");
}