Home Forums Front-end Issues Trying to sort Custom Post with date (date picker) for simple event display


Trying to sort Custom Post with date (date picker) for simple event display

  • Hey guys, I feel like I’ve tried everything and I can’t get my WP_Query to sort by date that is selected via date picker. I have read the documentation on the Date Picker and looked at multiple 3rd party tutorials and I know I’m close. I am hoping someone here will be able to spot my error.

    In this example I am just trying to display the next scheduled event. I do not have an end date or end time because I don’t need one and want to keep the admin as simple as possible.. Everything is displaying the way I want it, it’s just not showing the next post based on date.

    Here is my code so far:

    $today = current_time('Ymd');								
    	$args = array(
    		'post_type' => 'upcoming',
    		'post_status' => 'publish',
    		'posts_per_page' => '1',
    		'meta_query' => array(
    			'key' => 'date',
    			'compare' => '>=',
    			'value' => $today,
    		'meta_key' => 'date',
    		'orderby' => 'meta_key',
    			'order' => 'ASC',
    		'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
    	$query = new WP_Query($args);
    	if ($query->have_posts()) :
    	while ($query->have_posts()) : $query->the_post(); 
    	<div class="next-class">
    		<div class="next-cal-date">
    			$date = DateTime::createFromFormat('d/m/Y', get_field('date'));
    			$time = DateTime::createFromFormat('g:i a', get_field('time'));
    			<div class="topic-header"><?php echo $date->format('D') ?></div>
    			<div class="time"><?php echo $time->format('g:i') ?><div class="ampm"><?php echo $time->format('a') ?> C.S.T.</div></div>
    		<div class="topic-header">CLASS</div>
    		<div class="class-title">
    		$terms = get_the_terms( $post->ID , 'class' );
    		foreach ( $terms as $term ) {
    		echo $term->name;
    		} ?>
    		<div class="clearfix"></div>
    		<div class="class-topic">
    		<div class="class-topic-lead">
    			<?php the_title(); ?>
    		<div id="getting-started"></div>
    		<script type="text/javascript">
    		  .countdown("<?php echo $date->format('Y/m/d'); echo " "; echo $time->format('g:i a') ?>", function(event) {  
    			  event.strftime('%D days %H:%M:%S')
    	<?php endwhile; ?>
    	<?php else : ?>
    		Next Class Not Available
    	<?php endif; ?>
    <?php wp_reset_postdata(); ?>

    If you guys can spot my error I would be very thankful..

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.