Currently, the posts of my website are ordered alphabetically by title:
/* Order Posts Alphabetically */
function prefix_modify_query_order( $query ) {
if ( is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'prefix_modify_query_order' );
Now, I want to sort the posts alphabetically by title (ascending), but also by date (descending).
Like this example:
- AUDI A1 Ambition 1.4 (posted in 01/01/17)
- AUDI A1 Ambition 1.4 (posted in 01/01/16)
- AUDI A1 Ambition 1.4 (posted in 01/01/15)
- BMW 120i Active Flex 2.0 (posted in 01/01/17)
- BMW 120i Active Flex 2.0 (posted in 01/01/16)
- BMW 120i Active Flex 2.0 (posted in 01/01/15)
- Citroen...
Changing the orderby
parameter to $query->set( 'orderby', 'date title' );
does not resolve my problem because I need to show the most recent posts first.
I would appreciate any other ideas.