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


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(
    if (have_rows('flex_field')) {
      while (have_rows('flex_field')) {
        $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
          } // end if get sub field
        } // end foreach sub field
        if (!$has_content) {
          // this layout has no content
          // skip it
        } // 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)

You must be logged in to reply to this topic.