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
1 Answer
Reset to default 4As 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
评论列表(0条)