ACF Events with Date Field



// find date time now
$date_now = date('Y-m-d H:i:s');
$time_now = strtotime($date_now);

// find date time in 7 days
$time_next_week = strtotime('+365 day', $time_now);
$date_next_week = date('Y-m-d H:i:s', $time_next_week);

    $call_args = array(
        'post_type'         => 'events',
        'posts_per_page'    => $posts_per_page,
		'order'				=> 'ASC',
		'orderby'			=> 'meta_value',
		'meta_key'			=> 'event_start',
		'meta_query' 		=> array(
			array(
		        'key'			=> 'event_start',
		        'compare'		=> 'BETWEEN',
		        'value'			=> array( $date_now, $date_next_week ),
		        'type'			=> 'DATETIME'
		    )
	    ),
		'meta_type'			=> 'DATETIME'
    );

   $custom_query = new WP_Query( $call_args ); ?>


            // get today's date
            $today = date( 'Y-m-d' );
 
            // get posts
            call_args = get_posts(array(
                'post_type'         => 'events',
                'posts_per_page'    => -1,
                'meta_key'          => 'event_date_start',
                'meta_value'        => date('Y-m-d'),
                'orderby'           => 'meta_value',
                'order'             => 'ASC',
                'meta_compare'      => '>=',
                'value'             => $today,
                'type'              => 'DATE',
            ));

   $custom_query = new WP_Query( $call_args ); ?>

Comments