I don’t understand how to get the value of Radio Button fields top_and_bottom_padding
from a Group section_settings
within my Flexible Content field page_content
.
I would like to assign the values to variables to be easily re-used like this;
<?php if (get_row_layout() == 'page_content') :
$sectionPadding = get_sub_field('top_and_bottom_padding');
?>
You need to get the field “section_settings” and then get the sub field “top_and_bottom_padding” from that. This can be done in a few ways.
// get sections settings as an array
$section_settings = get_sub_field('section_settings');
$sectionPadding = $section_settings['top_and_bottom_padding'];
// loop group field
if (have_rows('section_settings')) {
// always true for group field
while (have_rows('section_settings')) {
// always happens one time for group field
the_row();
$sectionPadding = get_sub_field('top_and_bottom_padding');
}
}
// get field directly
// to be honest, I don't know if this will work with nested fields
// format here is "{$parent_field_name}_{$child_field_name}"
$sectionPadding = get_sub_field('section_settings_top_and_bottom_padding');
Thanks for the thorough examples @hube2! The get sections as an array code works perfectly for my needs.