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
- Can wp_query return posts meta in a single request?
- WP_Query orderby date not working
- compare meta_query in get_posts arguments
- Order by DESC, ASC in custom WP_Query
- 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
- Getting attachments by meta value
- WP_Query ordered by custom field that is a date string?
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- meta_key and meta_value not working together
- 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
- Meta query with order by another custom field
- getting posts and number by specific meta value in multiple meta
- How can I pick a single post from the latest 3?
- How do I sort posts with multiple pages
- Order WP_Query by multiple fields, subtracting them from one another
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Order By table field comment_status in WordPress > 4.0
- How to Filter Posts by Custom Fields?
- Complex WP_Query order request: DESC by day, but then ASC by time
- How can I sort posts by the date and a custom meta field?
- WP_Query orderby author__in
- How to orderby multiple meta fields if some fields are empty
- Fetch Record based on meta key dates
- Sort wordpress custom posts based on meta value
- Large AND OR query timing out
- Categorising search results based on Custom Fields
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- Debugging wp_query orderby for taxonomy
- wp_query get data from advanced custom field in wordpress
- WP Query – order posts by meta field first and then order the rest
- How to compare a date in custom field with today’s date in custom WP_Query?
- Advanced WP_Query with meta_query, orderby?
- Conditional operator OR not working with custom fields
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Order is breaking wp_query
- WP ForLoop to compare meta information of posts to determine what post to display
- Display posts with specific value first in query
- get_posts custom field
- wp_query posts with custom fields number smaller than
- Posts query according to meta box date
- create metabox to activate slider
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Querying a large number of posts including their custom fields data
- Filtering by multiple conditions in the loop
- Orderby two meta fields not working
- orderby ignored by wp_query
- Query multiple post types, but different order for each
- Order by the first array within a meta_query
- Query ACF relationship field – Comparator IN – Value array
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- display ACF repater field in archive page
- Categories In English version showing not canonical URL, instead shows query search result
- Custom order of posts in wp_query and different taxonomies
- WordPress Query custom ordering by temporary variable
- Comparing Meta Field date in WPQuery using Meta_Query?
- Query against multiple locations within single custom post type post
- Order by meta date with a thousanth of a second defaults to post order
- WP_Query, ACF field and array
- How to get_comments() ordered by date and parent?
- Order by Date Custom Field
- WP Query. Ordering posts by another post types meta
- using custom meta user data to run queries in WordPress
- Best way to query posts and order by relevancy to query
- wp_query sorting – one specific meta_key value at last and then sort by create date
- Meta key in wp_query bug?
- query_posts based on a meta_key
- Order posts by more than one variable (meta_key and publish date AND time)
- Create custom order sortby based on array of id
- Wrap group of wp query posts to parent div by date/year
- Sort by meta key within same day
- Using custom field as ‘orderby’ value causing post grouping by publish date
- WP_Query to show post from a category OR custom field – Not 100% answered
- Sorting Posts with meta value not working
- Show sticky post before other WP_Query
- 404 on Pages for Custom Post Type & Query_Posts
- Get posts by meta value except one post [closed]