Y-m-d
,
function wh_posts_orderby($orderby, $query) {
if ($query->get('orderby') != 'yyyymmdd_date_format')
return $orderby;
if (!( $order = $query->get('order') ))
$order = 'ASC';
global $wpdb;
$fieldName = $wpdb->postmeta . '.meta_value';
return "STR_TO_DATE(" . $fieldName . ", '%Y%m%d') " . $order;
}
add_filter('posts_orderby', 'wh_posts_orderby', 10, 2);
^ ^ functions.php
.
( YYYYMMDD)
$auj = date('Ymd');
$args = [
'category_name' => 'evenements',
'posts_per_page' => 3,
'meta_key' => 'date_de_fin',
'orberby' => 'yyyymmdd_date_format',
'order' => 'ASC',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'date_de_fin',
'value' => $auj,
'compare' => '>=',
'type' => 'DATE'
],
]
];
$queryEvent = new WP_Query($args);
if ($queryEvent->have_posts()) :
while ($queryEvent->have_posts()) : $queryEvent->the_post();
endwhile;
endif;
orderby meta_value?
, !