Support

Account

Home Forums Add-ons Repeater Field True/False in Repeater always returning false

Solved

True/False in Repeater always returning false

  • I’ve made a repeater loop for service providers, which is working fine, but for the life of me I can’t figure out why the true/false is always returning false.

    The live URL
    The prototype

    The true/false item in the Prototype is the pink “‘what’s up’ walk-in” text. In the code, I’ve just put ‘yes’ and ‘no’ for true and false for testing.

    <div class="table-1 agencies-table">
    				<table width="100%">
    						<thead>
    							<tr>
    								<th align="left" class="service-provider-column">Service Provider</th>
    								<th align="left" class="address-column">Address</th>
    								<th align="left" class="phone-number-column">Phone Number</th>
    							</tr>
    						</thead>
    					<tbody>
    						
    						<?php if( have_rows('agencies') ): ?>
    						<?php while( have_rows('agencies') ): the_row(); ?>
    							
    						<tr>
    							<td align="left">
    								<div class="name">
    									<h3><?php the_sub_field('agency_name'); ?></h3>
    								</div>
    								<div class="whats-up">
    									
    									<?php if ( 'yes' == get_field('whats_up_walk_in') ): ?>
    										Yes
    									<?php else: ?>
    										No
    									<?php endif; ?>
    									
    								</div>
    								<div class="website fusion-button-wrapper fusion-alignleft">
    									<a class="fusion-button button-flat fusion-button-square button-xlarge button-custom button-1" href="<?php the_sub_field('agency_website'); ?>" target="_blank">Visit website <i class="fa fa-external-link button-icon-right"></i></a>
    								</div>
    							</td>
    							<td align="left">
    								<div class="fusion-fa-align-left"><i class="fa fontawesome-icon fa-map-marker circle-no" style="font-size:20px;margin-right:7px;color:#173a64;"></i></div>
    								<div class="address">
    									<?php the_sub_field('agency_address'); ?>
    								</div>
    							</td>
    							<td align="left">
    								<div class="phone">
    									<i class="fa fontawesome-icon fa-phone circle-no" style="font-size:20px;margin-right:7px;color:#173a64;"></i> <?php the_sub_field('agency_phone_number'); ?>
    								</div>
    							</td>
    						</tr>
    						
    						<?php endwhile; ?>
    						<?php endif; ?>
    
    					</tbody>
    				</table>
    			</div>
  • G’day Mate,

    the true/false fields always return boolean regardless of what you put in the field setting. The field setting is only for admin UI, and has nothing to do with the return value.

    So, you code really only need to check if the return is truethy, not if it’s equal to ‘yes’:

    
    <?php if ( get_field('whats_up_walk_in') ): ?>
    	Yes
    <?php else: ?>
    	No
    <?php endif; ?>
    
    // or just
    <?php echo get_field('whats_up_walk_in')? 'yes' : 'no'; ?>
    

    Cheers

  • Thanks for replying @gummiforweb!

    I tried what you suggested (both things), and everything is still coming up as “No”. For example, East Metro Youth Services should be yes.

    I feel like there’s something else going on. I’ve tried multiple versions of the code (pretty much everything I could find on Google), and it all just returns as false.

    I’m not really sure what else to check other than making sure it is in fact checked ‘yes’ in the post itself. Do you have any suggestions?

  • if whats_up_walk_in is a sub field of the repeater then get_field('whats_up_walk_in') should be get_sub_field('whats_up_walk_in')

  • Ah! Amazing! Didn’t catch that. Thank you so much!

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

The topic ‘True/False in Repeater always returning false’ is closed to new replies.