richcon
Member
Posted 11 months ago #
I'm making a list display of 'events' (using custom post types), and there's meta fields for beginning date and ending date (each storing the date as an integer usable with PHP's date() function). I want to show current and upcoming events, so events whose 'end date' meta field is greater than or equal to the current date.
I also want to order events by start date, so how can I order by a meta field?
Thanks to anyone who can point me in the right direction!
Richard
Peter vanDoorn
Member
Posted 11 months ago #
Here's how I do it with a modified WP_Query:
<?php $args = array( 'post_type' => 'events',
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'event-date-start' ); ?>
<?php $eventslist = new WP_Query(); ?>
<?php $eventslist->query( $args ); ?>
The important bit is meta_key which tells it to look at the custom field called 'event-date-start' (in my case, yours will no doubt be different!)
Hope that helps
Peter