I'm trying to only proceed past the first IF statement if there is content in the sub field called INSTRUCTION, which seems to not work. It works if I remove && !empty(the_sub_field('instruction')


if( have_rows('instructions_group') && !empty(the_sub_field('instruction')) ): 


    <div id="instructions-group0" class="instructions-group">                


    if( have_rows('instructions_group') ):

        while ( have_rows('instructions_group') ) : the_row();

        $instructionphoto = get_sub_field('instruction_photo');
        $instruction = get_sub_field('instruction');
        $size = 'recipe-featured';
        $thumb = $instructionphoto['sizes'][ $size ];
        $width = $instructionphoto['sizes'][ $size . '-width' ];
        $height = $instructionphoto['sizes'][ $size . '-height' ];
        $alt = $instructionphoto['alt'];

        if( !empty($instruction) ) : ?>

            <li class="instruction">

                <div class="instruction-wrap">

                    <?php if( !empty($instructionphoto) ) : ?>

                        <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />

                    <?php endif; ?>

                    <div class="instruction-txt"><?php echo $instruction; ?></div>












1 Answer 1


As seen on ACF documentation, to check for a value before displaying it, simply use:

<?php if( get_field('field_name') ): ?>
    <p>My field value: <?php the_field('field_name'); ?></p>
<?php endif; ?>

So in your case, you are already getting the sub_field into $instruction, so simply use this:

 if( $instruction) ) : 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.