You can add a posts_orderby
filter to flip the meta_value:
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 );
Related Posts:
- Order posts by date and then by custom field
- Revolution Slider Orderby Two Custom Fields
- Order Posts by meta value AND published date
- Understanding the orderby in WP_Query?
- Order by empty custom field
- meta_value_num not ordering all items
- Sorting posts by Multiple custom fields in defined order
- Order 2 meta_queries differently in WP_Query?
- Order Custom Field by Price
- query_posts with sorting on a custom datestamp
- WP_Query sort by ACF date field (newest first) with blank dates first
- Sort wp_query of two post types using meta datefield for one and date for the other – possible?
- WP_Query – Order results by meta value
- Can wp_query return posts meta in a single request?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP_Query orderby date not working
- Meta query with string starting like pattern
- compare meta_query in get_posts arguments
- Order by optional meta key?
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Sorting: custom query with orderby meta_value_num THEN by title
- Order by DESC, ASC in custom WP_Query
- WP_Query order by multiple meta keys & fields
- Function in array as arguments for WP_Query
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- WP_Query to show post from a category OR custom field
- How to get order of posts?
- Order posts by ID in the given order
- Custom WP_Query order by post_meta and (author) user_meta
- Getting attachments by meta value
- meta_query where value is equal to given value
- How to order posts tag by tag?
- How do I order pages and categories by ID or name in the same query?
- Get_post() with meta_key when compare is a date
- WP_Query ordered by custom field that is a date string?
- querying with custom meta field with meta_query
- Group posts by custom field
- WP_Query sort by comment meta data
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Trying to perform complex custom field query with order by set to field value
- Order Posts by Closest Numeric Values
- Order posts by tags count?
- Merge 2 args in one WP_Query and order it by date
- Orderby = none not working [duplicate]
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- WP_query ‘orderby=none’ Problem
- Sorting Posts by custom field
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Query two post types and order by two different date fields
- Order posts ascending with number in title
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Order by the results of a function with WP_query
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- How to order posts in wp_query by a meta_value of the corresponding author
- Order by meta_key in custom post type doesn’t affect the query
- Order by menu structure
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- meta_key and meta_value not working together
- How can i make WP_Query return post image and categories?
- WP_Query order by date in meta_value
- Custom Field sort not working (WP 3.8.1)
- How to use order RAND() on WordPress?
- Show all parents and children in custom post type in right order
- wp_query with multiple custom fields
- Ordering by meta_value AND date NOT WORKING with wp_query
- WP_Query orderby breaks when using AJAX?
- Order WP Query posts by custom order calculated from post meta values
- How add a custom posttype name using ACF field to a query post array
- Filtering posts by custom field value not working
- Custom Post order for homepage
- Meta query with order by another custom field
- Change default ordering of taxonomy terms – pre_get_terms
- Display link to taxonomy archive only if it has posts with certain custom field values
- getting posts and number by specific meta value in multiple meta
- Ordering Posts Type A by Custom Fields of related Post Type B
- WordPress WP_Query orderby being overwritten
- WP_Query Order by Specific Post ID First
- How can I pick a single post from the latest 3?
- Wp query orderby ‘title’ doesn’t work
- How can I order Wp_Query hierarchically?
- How do I sort posts with multiple pages
- Sorting posts DESC based on the number of comments using WP_Query
- Search Posts with Custom Fields as query
- wp_query add arguments using array_push if variable met
- Order WP_Query by multiple fields, subtracting them from one another
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- Group WP_Query by meta_key date
- How To Fix WP Query Returns Results But Shouldn’t?
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- exclude posts with a specific custom field and value
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- Orderby ASC changes to DESC in WP_Query
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Add quicklink to in the Admin posts page where I can query by a meta_key