Home Forums General Issues Condition for acf and the_post() content


Condition for acf and the_post() content

    • Ariya

    • May 5, 2020 at 3:53 pm

    i use acf for single post.

    i need this:
    when acf fields exist in post, didn’t load the_post() content and Reverse when acf fields not exist in post, load the_post() content normaly.

    how can make Condition for this?
    please help me.

  • Hi you could do something like this:

    <?php if( get_field('field_one') || get_field('field_two') ) { ?>
    <?php the_field('field_one'); ?> <?php the_field('field_two'); // Display the fields not the content ?>
    <?php } else { ?>
    <?php the_content(); ?>
    <?php } ?>

    So we check to see if any fields exist and if they do we display them, if not we display the post’s content.

    I hope that helps!

    • Ariya

    • May 6, 2020 at 2:25 pm

    work like a charm <3
    thanks a lot

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.