I found out the answer myself.
There are other filters that let you adjust the query before it’s run:
http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_clauses
The posts_clauses filter runs before the query gets executed and is essentially the sum of all filters that run immediately before it.
Apart from posts_clauses, there are several more precise filters that modify only a single specific clause:
- posts_where_paged
- posts_groupby
- posts_join_paged
- posts_orderby
- posts_distinct
- post_limits
- posts_fields
So in my case, all I had to do was to use posts_orderby filter.
Related Posts:
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- pre_get_posts order by not working
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- WP Query – order posts by meta field first and then order the rest
- Child pages not affected by orderby
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- Custom WP_Query order by post_meta and (author) user_meta
- How to order posts tag by tag?
- Slow SQL_CALC_FOUND_ROWS Query
- SQL Statement generated by WP_Query not producing expected results
- Order posts by tags count?
- Orderby = none not working [duplicate]
- Sorting Posts by custom field
- Order posts by date and then 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
- Recommended way to drop a pending query (in pre_get_posts)?
- Order by the results of a function with WP_query
- How to order posts in wp_query by a meta_value of the corresponding author
- Order by menu structure
- WP_Query order by date in meta_value
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Show all parents and children in custom post type in right order
- Order WP Query posts by custom order calculated from post meta values
- Searching through different categories on different pages code is not working
- How to display future posts – modified query still yields 404
- Meta query with order by another custom field
- Wp query orderby ‘title’ doesn’t work
- How can I order Wp_Query hierarchically?
- How do I sort posts with multiple pages
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to choose between hooking into per_get_posts or into parse_query
- Store sticky post’s ids in a transient
- 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
- new WP_Query to get max price meta value not working
- WP_Query, pre_get_posts and offset
- Complex WP_Query order request: DESC by day, but then ASC by time
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Show scheduled posts in main loop but not in WP_Query?
- How to orderby multiple meta fields if some fields are empty
- Sort wordpress custom posts based on meta value
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- Shouldn’t I be able to modify the main query by this filter?
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- using pre_get_posts for search results not found
- Hide elements outside loop based on query
- Debugging wp_query orderby for taxonomy
- Advanced WP_Query with meta_query, orderby?
- How to Order a list of taxonomies? orderby?
- queried_object using pre_get_posts gets notices and warning
- date_query in pre_get_posts out of memory
- Sorting search results with custom dropdown
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Filtering by multiple conditions in the loop
- 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]
- orderby ignored by wp_query
- $wp_query->found_posts not returning correct value
- WP_Query, Paginate by Custom Field
- WP_Query orderby
- Replace wp_query with wp_user_query
- Block internal search queries with pre_get_posts and regex rules
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- is_user_logged_in not working from WP-API (wp-json)
- Search Exact on WordPress – Relevannsi Solution Not Working
- How to sort store location by specific category order in WP store locations
- order posts by a secondary query that counts items
- WP_Query random ordering not working since 5.4
- How can I re-query post_type and rewrite the url?
- Order by meta date with a thousanth of a second defaults to post order
- WP Query with meta queries
- WP Query. Ordering posts by another post types meta
- Woocomerce – Order products by float attribute in archive pages
- 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
- query_posts based on a meta_key
- Display three sequential posts on each page load, without repeating previous
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Order posts by more than one variable (meta_key and publish date AND time)
- Create custom order sortby based on array of id
- Modify query to exclude certain ids and certain parents and its corresponding children
- Sort by meta key within same day
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Order Custom Field by Price
- pre_get_posts or $where, which one to use?
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Order by multiple meta keys on wordpress
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- WP_Query with several meta_query-statements and order by meta_value
- Custom post types loop on a page template
- Pre_get_post on CPT archive page
- Get posts that were most recently tagged
- Search query alteration not working for meta values
- Why does wp_query only display the most recent post when using order ASC?
- WP_Query sort by ACF date field (newest first) with blank dates first
- new WP_Query with order args – no more distinction between categories