Home Forums Add-ons Flexible Content Field How to get Group fields from within a Flexible Content field


How to get Group fields from within a Flexible Content field

  • 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
        $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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.