• Resolved Guido

    (@guido07111975)


    Hi,

    I display some fields that are wrapped in a div container.
    I thought when using this condition, the container with fields is only displayed if present:

    $fields = get_field_objects();
    if ( $fields ) {
    <div class="fields-container">
    // my fields
    </div>
    }

    But the $fields array seems to be not empty, even when post/page has no fields.
    So what’s the best way to determine if post/page has fields?

    Guido

Viewing 3 replies - 1 through 3 (of 3 total)
  • ACF Support

    (@acfsupport)

    Hi there!

    ACF Support Team here. This forum is generally used by ACF users to help each other out.

    However, we would love to get more info on this, please can you create a ticket using our ?support form and we can look into it further.

    Thread Starter Guido

    (@guido07111975)

    Hi,

    Why leave this site, this way you keep other users out of the loop.

    Guido

    Thread Starter Guido

    (@guido07111975)

    Fixed it with this snippet:

    $fields = get_fields();
    $has_fields = false;
    if ( $fields ) {
    foreach( $fields as $field => $field_value ) {
    if ( !empty($field_value) ) {
    $has_fields = true;
    }
    }
    if ( $has_fields == true ) {
    // my container with fields
    }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.