Alphabetical ordering in "Category Archive" pages

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!

Hi @Draxdes,

Thanks for reaching out.

It may not work with WPML, you may still need additional coding for that to work and I recommend contacting a developer.

And you should set its order by title and not date.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.