This is very crude but should sort your posts by year (meta_value) and then by title. It does depend on how the query is setup so it will only work with the query below or with similar ones.
function alter_order_wpse_103181($order,$qry) {
remove_filter('posts_orderby','alter_order',1,2);
$order = explode(',',$order);
$order = implode( ' ASC,',$order);
return $order;
}
add_filter('posts_orderby','alter_order_wpse_103181',1,2);
$q = new WP_Query();
$q->query( array(
'post_type' => 'movies',
'distribution' => 'companyA',
'meta_key' => 'year',
'orderby' => 'meta_value_num title',
'order' => 'ASC',
'posts_per_page' => -1,
'post_status' => 'publish',
));
var_dump($q->request);
Related Posts:
- Sorting: custom query with orderby meta_value_num THEN by title
- Meta query with order by another custom field
- Help ordering Post loop by two meta values
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to get order of posts?
- Custom WP_Query order by post_meta and (author) user_meta
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Order WP Query posts by custom order calculated from post meta values
- Order Posts by meta value AND published date
- How to orderby meta_value_num with dollar ($) sign
- How do I sort posts with multiple pages
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- How to orderby multiple meta fields if some fields are empty
- 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
- Understanding the orderby in WP_Query?
- Order ascending is ignored in meta query?
- meta_value_num not ordering all items
- How to filter a query by multiple meta keys and order by other meta keys
- Advanced WP_Query with meta_query, orderby?
- Sorting search results with custom dropdown
- orderby ignored by wp_query
- Sort posts using multiple custom fields and menu_order in single query?
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- Order (by ASC) posts with meta_key so posts without values are last
- How to sort store location by specific category order in WP store locations
- How to sort wordpress posts already selected by WP_QUERY
- WordPress Query custom ordering by temporary variable
- Meta query orderby meta_value_num sorting by role first
- WP_User_Query Orderby Not Working
- Order by value of Custom Field using url string
- WP Query with meta queries
- Order 2 meta_queries differently in WP_Query?
- Sorting with meta_query and multiple, optional meta keys
- WP Query. Ordering posts by another post types meta
- wp_query sorting – one specific meta_key value at last and then sort by create date
- Display three sequential posts on each page load, without repeating previous
- Best way to Order Post in Home without a plugin
- Using orderby with 2 meta keys
- query_posts with sorting on a custom datestamp
- Sort Posts with custom meta key by default which is currently set as optional
- WP_Query with several meta_query-statements and order by meta_value
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to query posts based on lat-lng coordinate as post meta?
- Set Alias for meta_query arguments in get_posts()
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Using custom meta_query with relation not working as expected
- WP_Query meta_query where meta value ends in space
- Nested query inside Logical operator OR not working in meta_query
- What is an efficient way to query based on post_meta?
- How do I create my own nested meta_query using posts_where / posts_join?
- Sort by meta key on archive page
- Order posts by meta value and Date
- Query sticky posts with thumbnails
- Show all parents and children in custom post type in right order
- How to make orderby ‘meta_value_num’ OPTIONAL?
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to do meta_query for attachments?
- Order By table field comment_status in WordPress > 4.0
- Why isn’t my `meta_query` array functioning properly?
- Overwrite YoastSEO meta-tags with another page’s [closed]
- WP_query sorting can’t sort danish letters (æ, ø, å)
- Order by meta value (numeric value lower to higher)
- Large AND OR query timing out
- WP_Query with different postmeta filter for each categories
- Debugging wp_query orderby for taxonomy
- Issues with search after added meta_query
- Display posts with specific value first in query
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- How to create dynamic value in WP_Query meta_query
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- query post by author gender
- Filtering by multiple conditions in the loop
- How do I add an item to the WP admin menu?
- Multiple meta query from array
- WP_Query with 4 post meta field arguments gives 500 internal server error
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- Custom meta_query order for Elementor based on post meta key [closed]
- ElasticPress is (aparently) messing with my search filters
- Multiple meta_query not returning rows
- Check for not NULL not working in meta query
- Get unique post by meta value using wp_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
- Order by Date Custom Field
- Get posts meta_query by repater field
- Query 3 meta_key and orderby
- query_posts based on a meta_key
- Order posts by more than one variable (meta_key and publish date AND time)
- Sort by meta key within same day
- meta_query not working with the_content()
- Get closest event where meta_key field is an array
- Order by multiple meta keys on wordpress
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?