Support

Account

Home Forums Add-ons Flexible Content Field Hide flexible content is all fields are empty

Helping

Hide flexible content is all fields are empty

  • Hi I know that I can use a conditional statement to check if a particular field is empty.

    But how would I do this if I want to check that all fields within a flexible content loop are empty?

  • You’d need to check every field. I would probably do something like

    
    $sub_fields = array(
      'create',
      'an',
      'array',
      'of',
      'sub_field',
      'names',
    );
    if (have_rows('flex_field')) {
      while (have_rows('flex_field')) {
        the_row();
        $has_content = false;
        foreach ($sub_fields as $sub_field()) {
          if (get_sub_field($sub_field)) {
            // flex field has content
            $has_content = true;
            // do not need to continue loop once you find content
            break;
          } // end if get sub field
        } // end foreach sub field
        if (!$has_content) {
          // this layout has no content
          // skip it
          continue;
        } // end if !content
        // *********************************************
        // code to display layout here
        // *********************************************
      } // end while have rows
    } // end if have rows
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Hide flexible content is all fields are empty’ is closed to new replies.