ACF Repeater Field, need IF statement for if sub field has content

I'm trying to only proceed past the first IF statement if there is content in the sub field called INSTRUCTION, whi

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')

<?php

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

    ?>

    <div id="instructions-group0" class="instructions-group">                
    <h2>DIRECTIONS:</h2>
    <ol>

<?php   

    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>

                </div>

            </li>

        <?php 

        endif;

        endwhile;

         ?>

        </ol>
    </div>

    <?php   

    endif; 

endif;

?>

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')

<?php

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

    ?>

    <div id="instructions-group0" class="instructions-group">                
    <h2>DIRECTIONS:</h2>
    <ol>

<?php   

    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>

                </div>

            </li>

        <?php 

        endif;

        endwhile;

         ?>

        </ol>
    </div>

    <?php   

    endif; 

endif;

?>
Share Improve this question edited Jun 29, 2019 at 19:56 adsf asked Jun 29, 2019 at 19:42 adsfadsf 872 gold badges4 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

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) ) : 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745358659a4624259.html

相关推荐

  • ACF Repeater Field, need IF statement for if sub field has content

    I'm trying to only proceed past the first IF statement if there is content in the sub field called INSTRUCTION, whi

    12小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信