WP_Query ordered by a date which is held as a meta key
-
Hi,
I’m currently coding an event plugin and want to display the events. However, when I get them to display, it shows all the events in the order of when they were created and, even past events.
What I want is to be able to order the posts so that the next event is first and so that no events which have passed are shown.
My issue is that the date is stored in a meta_key called ‘WooCommerceEventsDate’ as ’12 February 2016′ for example.Following a tutorial from another forum article, I came up with this but it doesn’t show anything.
$args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'post_status' => 'publish', 'meta_key'=>'WooCommerceEventsDate', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( array( 'value' => date('j F Y',strtotime("today")), 'compare' => '>=', 'type' => 'DATE' ) ) );
Anyone got any ideas?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP_Query ordered by a date which is held as a meta key’ is closed to new replies.