WP_Query with meta key and orderded by meta key

I have a custom post type for news and events, and I am trying to only display the most recent upcoming event based off its custom field of 'date'. I am able to display only events but not incorporate 'orderby' to sort by the meta key of date compared to today's date. <?php $args = [ 'post_type' => 'news-events', 'showposts' => 1, // Show only Events 'meta_key' => 'news_or_event', 'meta_value' => 'Event', // Order by date not working "meta_key" => "date", "meta_value" => date("Ymd"), "meta_compare" => ">=", ]; $latest_event = new WP_Query($args); ?> <?php if ($latest_event->have_posts()): ?> <?php while ($latest_event->have_posts()): $latest_event->the_post(); ?> //Show Latest Current Event <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query();?> I have also tried using meta_query: <?php $args = [ 'post_type' => 'news-events', 'showposts' => 1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'news_or_event', 'value' => 'Event', 'compare' => '=' ), array( 'key' => 'date', 'value' => date("Ymd"), 'type' => 'Date', 'compare' => '>' ) ), "meta_key" => "date", "meta_value" => date("Ymd"), "meta_compare" => ">", ]; $latest_event = new WP_Query($args); ?> <?php if ($latest_event->have_posts()): ?> <?php while ($latest_event->have_posts()): $latest_event->the_post(); ?> //Show Latest Current Event <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query();?>

Comment (0)

You’ll be in good company