Support

Account

Home Forums ACF PRO How to hide sub fields in a field group…

Helping

How to hide sub fields in a field group…

  • I have a field group (repeater field type) set up (titled “Units”) with sub fields; sq footage, floor plans and availability (this is a yes/no selection). I have the availability sub field to display on the front end as “Yes” or “No” but I don’t want the Units to show up on the front end that have the “No” availability selected. I am not sure what to do to get the “No” units to hide when that is selected as well as the whole field group to hide if there are no “Yes” units in the group.

    Front end of what I am talking about

  • Very hard to tell without code, but I would probably use an output buffer, and also only output the rows of the table that have available set to yes.

    
    ob_start();
    $something_available = false; // flag to note something is available
    if (have_rows('units')) {
      while (have_rows('units')) {
        the_row();
        if (get_sub_field('available')) {
          // this one is available
          // output this row of the table
          // and set our flag to true
          $something_available = true;
        } // end if available
      } // end while have_rows
    } // end if have_rows
    $content = ob_get_clean();
    if ($something_available) {
      // only output if something is available
      echo $content;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to hide sub fields in a field group…’ is closed to new replies.