Код: Выделить всё
// From my custom meta box. Shows the type of field that
// the user enters the date into. The prefix is _cmb_
array(
'name' => 'Event Date',
'id' => $prefix . 'event_date',
'type' => 'text_date'
),
---- // -----
// Grab the date that's input from the user in the
// Custom Meta Box and Convert the text_date to
// YYYYMMDD format
if ( $field['type'] == 'text_date' ) {
$new = date('omd', strtotime($new));
}
Код: Выделить всё
// Tour Dates Loop
$args = array(
'post_type' => 'event',
'meta_key' => '_cmb_event_date',
'order_by' => 'meta_value_num',
'order' => 'DESC'
);
$tourDates = new WP_Query( $args );
Я пытался преобразовать _cmb_event_date в целое число, но мне не удалось получить чтобы работать правильно. Я подумал, что, возможно, даты отсортированы неправильно, потому что они были не целым числом, а строкой.
Я просмотрел кучу сообщений здесь, в Stack. и я не могу найти ответ, который работает для меня. Любая помощь очень ценится! Если вам нужен дополнительный контекст для кода, дайте мне знать.
Подробнее здесь: https://stackoverflow.com/questions/116 ... ue-by-date