Support

Account

Home Forums General Issues Date Picker order by date

Helping

Date Picker order by date

  • I am having trouble with ordering posts by the date picker field. I am also only displaying “upcoming events” in this feed. My field name is “event_date”. This is the code I have:

     $args = array( 	
        'post_type'      => 'post',
        'cat' => 1,
        'meta_query'   => array(
      	'relation'      => 'AND',
        array(
          'key'         => 'event_date',
          'value'       => date('Ymd'),
          'compare'     => '>',
          'type'        => 'date'
        ),
        'posts_per_page' => -1,    
        'meta_key' =>'event_date',
        'orderby' => 'meta_value_num',
        'order'          => 'ASC',
     ));
    
    $upcoming= new WP_Query( $args );
    $current_post_id = $post->ID;
    if ( $upcoming ->have_posts() ) : ?>
    <h2>Upcoming Events</h2>
    <?php $exclude = array(); ?>
    
     <?php while ( $upcoming->have_posts() ) : $upcoming ->the_post(); ?>
     <?php $exclude[] = $post->ID; ?>
    
    				
    	<h3><?php the_title();?><br/>
    	<span class="price"><?php the_field('location');?>, <?php the_field('event_date');?></span></h3>
    	<?php the_excerpt();?>
    	<a class="buttonblue" href="<?php the_permalink();?>">more details</a>
    
    <?php endwhile;  endif; wp_reset_postdata(); ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.