Hello everybody,
how can we have alphabetical ordering for posts in “Category Archive” pages?
And would it work also for WPML translated version of those Category Archives?
We’ve added the following code in function.php, but doesn’t seem to work:
add_action( 'pre_get_posts', 'custom_reverse_post_order' );
function custom_reverse_post_order( $query ) {
if ( is_admin() )
return;
if ( $query->is_main_query() && is_archive() && ! is_post_type_archive() && ($query->query_vars['category_name'] == 'fashion-lifestyle' || $query->query_vars['category_name'] == 'beauty-groceries-other' || $query->query_vars['category_name'] == 'yacht-services' || $query->query_vars['category_name'] == 'restaurants-cafes') ) {
$query->set( 'orderby', 'date' );
$query->set( 'order', 'ASC' );
}
}
Thanks!