This is the current query:
$loop = new WP_Query(array('post_type' => 'event', 'posts_per_page' => -1, 'order' => ASC));
These are some of my custom fields:
$event_price = $custom["event_price"][0];
$event_start_date = $custom["event_start_date"][0];
$event_end_date = $custom["event_end_date"][0];
What I want to be able to do is run the query but sort by my event_start_date ascending.
Jens Filipsson answers:
Something like this should work:
$loop = new WP_Query(array('post_type' => 'event', 'posts_per_page' => -1, 'meta_key' => 'event_start_date', 'orderby' => 'meta_value', 'order' => ASC));
John Cotton answers:
Add meta_key= 'event_start_date' to your array.....
69developer comments:
So I add 'meta_key' => 'event_start_date' ?
Then what about the ordering by the event_start_date?
John Cotton comments:
orderby=meta_value_num&order=ASC
Oleg Butuzov answers:
new WP_Query(
array('post_type' => 'event',
'posts_per_page' => -1,
'order' => ASC,
'orderby'=>'meta_value_num',
'meta_key'=>'event_price'
)
);
if price is int
else case use just 'orderby'=>'meta_value'