Support

Account

Home Forums Add-ons Repeater Field Can't get “has_sub_field()” to work in a conditional

Helping

Can't get “has_sub_field()” to work in a conditional

  • Everything is working fine, except the <?php has_sub_field('vimeo_id'); ?> line. I want it so that if the user has filled out that field, it displays. Otherwise, nothing shows. However, when the user doesn’t fill out the field, it still shows. What have I done wrong?

    	<?php if( have_rows('project') ): ?>
    	 
    	    <ul>
    	 
    		    <?php while( have_rows('project') ): the_row(); ?>
    		 
    		        <li><a href="#<?php the_sub_field('project_name'); ?>"><?php the_sub_field('project_name'); ?></a></li>
    		        
    		    <?php endwhile; ?>
    	 
    	    </ul>
    
    	    <?php while( have_rows('project') ): the_row(); ?>
    
    	    	<div id="<?php the_sub_field('project_name'); ?>">
    
    		    	<?php has_sub_field('vimeo_id'); ?>
    
    					<iframe src="//player.vimeo.com/video/<?php the_sub_field('vimeo_id'); ?>?title=0&byline=0&portrait=0&color=ffffff" width="750" height="300" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    
    			</div>
    
    		<?php endwhile; ?>
    	 
    	<?php endif; ?>
  • Try changing it to:

    <?php if(get_sub_field(‘vimeo_id’)) { ?>

    <iframe>embed code</iframe>

    <?php } ?>

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

The topic ‘Can't get “has_sub_field()” to work in a conditional’ is closed to new replies.