Support

Account

Home Forums General Issues Meta query help, how to get the FieldName of an ACF date field inside of a group

Unread

Meta query help, how to get the FieldName of an ACF date field inside of a group

  • I created a custom post for the Event. I want to use the compare in meta_query to only show events that are today or in the future.
    The start_date field is an ACF date picker inside of a group name date_and_time.

    for some reason, this is not working and I can’t figure out why. Any help will be greatly appreciated.

    			<?php
    
    				$todays_date = date('Ymd');					
    				//Start date is inside of a group call Date and Time
    				$event_start_date = get_field('date_and_time')['start_date'];	
    
    				//Arguments for the event_query
    				 $args = array (
    					'post_type' => 'event',
    					'posts_per_page' => -1,
    					'meta_query' => array(
    						array(
    							'key' => $event_start_date,
    							'value' => $todays_date,
    							'compare' => '>='
    						),
    					),                
    				);
    
    				$event_query = new WP_Query( $args );
    
    								
    				if ( $event_query->have_posts() ) :
    					while ( $event_query->have_posts() ) : $event_query->the_post(); ?>
    
    					....Do something 
    
    					<?php endwhile; ?><!-- end the events while loop -->
    				<?php else : ?>
    				
              			<!-- If there are no more future event, then show this message -->
    					<?php _e( 'Sorry, there are no events.' ); ?>
    
          			
    				<?php endif; ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.