Support

Account

Home Forums Front-end Issues Conditional returns true for empty field

Solving

Conditional returns true for empty field

  • My post’s repeater field is empty:
    https://www.dropbox.com/s/41167csgr7vyyn4/Screenshot%202014-03-18%2023.25.02.png

    My conditional statement seems to be correct:

    <?php if ( 'content' == $settings['post_content'] || is_single() ) {
      if( have_rows('embedded_content') ): ?>
    
      <div class="embed_area">
    	  <div id="loopedSlider" class="magazine-slider has-pagination woo-slideshow" style="height:auto;">
    		  <ul class="slides">
    		  <?php while( have_rows('embedded_content') ): the_row(); ?>
    		      <?php $embedded_media = get_sub_field('embedded_media'); ?>
    		     <li class="slide">
    		      <?php $embedded_media_caption = get_sub_field('embedded_media_caption'); ?>
    		      <?php echo $embedded_media ?>
    		     <p class="embed_caption"><?php echo $embedded_media_caption ?></p>
    		     </li>
    		    <?php endwhile; ?>
    		  </ul>
    	  </div>
      </div>
    
       	<script type="text/javascript">
    	jQuery(window).load(function() {
    		var args = {};
    		args.useCSS = false;
    		args.animation = 'slide';
    		args.slideshow = false;
    		args.smoothHeight = true;
    		args.video = true;
    		args.manualControls = '.pagination-wrap .flex-control-nav > li';
    		args.start = function ( slider ) {
    			slider.next( '.slider-pagination' ).fadeIn();
    		}
    		args.prevText = '<span class="icon-angle-left"></span>';
    		args.nextText = '<span class="icon-angle-right"></span>';
    
    		jQuery( '.woo-slideshow' ).each( function ( i ) {
    			jQuery( this ).flexslider( args );
    		});
    	});
    	</script>
    
      <?php endif; ?>
    <?php }; ?>

    But the conditional is coming back positive anyway:
    https://www.dropbox.com/s/mt192ubux551xrd/Screenshot%202014-03-18%2023.26.04.png

    Thanks for any help you can provide.

  • With your conditional, you mean this:
    if( have_rows(’embedded_content’) ): ?

    I’m pretty sure It’s returning true because in your screenshot you actually have a row. In the settings of a repeater field you can define minimum rows and if you leave that empty, then you can have a repeater field without any rows.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Conditional returns true for empty field’ is closed to new replies.