add_filter('posts_orderby', 'posts_orderby');
function posts_orderby($orderby_for_query) {
global $wpdb;
$prefix = $wpdb->prefix;
$orderby_for_query = "LEFT(" . $prefix . "posts.post_date, 10) DESC, " . $orderby_for_query;
return $orderby_for_query;
}
This produces this query:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type="post" AND (wp_posts.post_status="publish") AND (wp_postmeta.meta_key = 'my_post_rating' ) GROUP BY wp_posts.ID ORDER BY LEFT(wp_posts.post_date, 10) DESC, wp_postmeta.meta_value+0 DESC
Related Posts:
- Sorting posts by custom date fields (non standard date format)
- 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
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- 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
- Custom WP_Query order by post_meta and (author) user_meta
- How to order posts tag by tag?
- WP_Query sort by comment meta data
- Trying to perform complex custom field query with order by set to field value
- WP_query ‘orderby=none’ Problem
- Sorting Posts by custom field
- Query two post types and order by two different date fields
- 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 menu structure
- meta_key and meta_value not working together
- 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
- Custom Post order for homepage
- Change default ordering of taxonomy terms – pre_get_terms
- Ordering Posts Type A by Custom Fields of related Post Type B
- Wp query orderby ‘title’ doesn’t work
- How can I order Wp_Query hierarchically?
- Sorting posts DESC based on the number of comments using WP_Query
- Search Posts with Custom Fields as query
- exclude posts with a specific custom field and value
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- How to make Meta Query case sensitive?
- Complex WP_Query order request: DESC by day, but then ASC by time
- WP_Query orderby not working with meta_value_num and menu_order
- Sort wordpress custom posts based on meta value
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- meta_query BETWEEN, but the range is stored in the custom field
- Get a list of posts with associated meta_value
- WordPress Comments sort by custom meta key
- Order by summing multiple values
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Order ascending is ignored in meta query?
- Search posts missing a particular custom field
- How to Order a list of taxonomies? orderby?
- Conditional operator OR not working with custom fields
- WP_QUERY with group by with custom fields
- Intiger meta value with ‘>=’ returns posts with lower value
- Posts query according to meta box date
- create metabox to activate slider
- Query posts using less than
- Query only displays one page_id
- Child pages not affected by orderby
- Display post meta conditionally based on it’s value
- Query using string from custom field as array value
- How to show list of posts with custom field value (a date) that are coming soon
- Randomly select one of last 3 posts
- WP_Query orderby random do not repeat infinite scroll – one loop
- how to retrieve WP_Query without ordering by date [duplicate]
- meta_query weird behaviour, static int will work, but not user data
- Woocommerce Shortcode which displays a table with product data
- WP_Query orderby
- 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 can I order a post query’s results based on the number of matching taxonomy terms?
- How to sort store location by specific category order in WP store locations
- Query posts by post type, author and post meta
- How to use the Term Object from a custom select field in a query
- How to sort wordpress posts already selected by WP_QUERY
- Trouble with serialized metadata
- WP_Query random ordering not working since 5.4
- Meta query orderby meta_value_num sorting by role first
- WP Query with meta queries
- Query post by Category and custom file (ACF)
- Problem with my loops
- Sort posts on custom field AND after that sort on date?
- Query by meta value (add a dropdown of all values)
- WP_Query sort by meta_value_num or date
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Display three sequential posts on each page load, without repeating previous
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Using orderby with 2 meta keys
- Custom search (wp query by custom fields)
- How do I display posts with specific value in a custom field into my loop?
- $args Orderby The number
- Custom Search Query – include only custom fields and title
- Order by multiple meta keys on wordpress
- WP_Query with several meta_query-statements and order by meta_value
- WP_Query – order with usort by custom meta
- Get posts that were most recently tagged
- Why does wp_query only display the most recent post when using order ASC?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- new WP_Query with order args – no more distinction between categories