Tag Archives: date picker

Custom post Type Query order by Date picker ACF

Query Custom Post Type with an Advanced Custom Fields Date Picker and order by that date.

<?php
	// current date
    $thedate = date("Ymd"); 
	
	// Start query
	$wp_query = new WP_Query();
    $wp_query->query(array(
    'post_type'=>'book_signing',
    'posts_per_page' => 10,
    'paged' => $paged,
	'meta_key' => 'date_of_signing',
    'meta_value' => $thedate,
    'meta_compare' => '>',
    'orderby' => 'meta_value',
    'order' => 'ASC'
));
    if ($wp_query->have_posts()) : ?>
    <?php while ($wp_query->have_posts()) : ?>
        
    <?php $wp_query->the_post(); ?>
    
    <?php 
		// Set some variables to set how to show the dates.
	$eventdate = DateTime::createFromFormat('Ymd', get_field('date_of_signing'));

 	?>
					
			<div class="booksigning">
             <h2><?php the_title(); ?></h2>
             <div class="eventdate"><?php echo $eventdate->format('M d'); ?></div>
            
            </div><!-- book signing -->		
                    
    <?php endwhile; ?>
        
        <div class="clear"></div>
    		<?php pagi_posts_nav(); ?>
        
    <?php endif; ?>