If/Else Statement for Advanced Custom Fields

<?php if( get_field(‘parent_repeater’) ) : while( has_sub_field(‘parent_repeater’) ) : $some_bool = get_sub_field(‘true’); $sf1 = get_sub_field(‘sub_field_1’); $sf2 = get_sub_field(‘sub_field_2’); if( $some_bool == true ){ echo $sf1 . $sf2; } else { echo $sf1; } endwhile; endif; ?> You must use the non-echoing version of the function. Use the get version. Also, I advise you to use … Read more

Can’t get “has_sub_field()” to work in a conditional [closed]

You need to use the has_sub_field() method inside an if() statement. I’ve only included the affected code below to highlight the specific changes required. if (has_sub_field(‘vimeo_id’)): // Added if() // … endif; You also need to a use the get_sub_field() function here as opposed to the has_sub_field() function: <iframe src=”https://player.vimeo.com/video/<?php echo get_sub_field(‘vimeo_id’); ?>”></iframe>

Show only the future event (Advanced Custom Fields)

You need a meta query. There’s also documentation on ACF for querying dates. <?php $event = new WP_Query( array( ‘post_type’ => ‘gacr-event’, ‘posts_per_page’ => 5, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘date’, ‘type’ => ‘NUMERIC’, // MySQL needs to treat date meta values as numbers ‘value’ => current_time( ‘Ymd’ … Read more