您可以添加posts_orderby
筛选以翻转meta\\u值:
function wpse174075_posts_orderby( $orderby, $query ) {
if ( $query->get( \'orderby\' ) != \'ddmmyy_date_format\' ) return $orderby;
if ( ! ( $order = $query->get( \'order\' ) ) ) $order = \'DESC\';
global $wpdb;
$mv = $wpdb->postmeta . \'.meta_value\';
// Note SUBSTR() position (2nd) arg is 1-indexed.
return \'CONCAT(SUBSTR(\' . $mv . \', 5, 2), SUBSTR(\' . $mv . \', 3, 2), SUBSTR(\' . $mv . \', 1, 2)) \' . $order;
}
add_filter( \'posts_orderby\', \'wpse174075_posts_orderby\', 10, 2 );
$posts = get_posts(array(
\'post_type\' => \'course\',
\'posts_per_page\' => -1,
\'meta_key\' => \'date-start\',
\'orderby\' => \'ddmmyy_date_format\',
\'order\' => \'DESC\',
\'suppress_filters\' => false,
));
remove_filter( \'posts_orderby\', \'wpse174075_posts_orderby\', 10 );