Skip Navigation

[Resolved] Sort order in german language

This thread is resolved. Here is a description of the problem and solution.

Problem:
Sort order in german language - change orderby settings for post type archive

Solution:
You can use WordPress standard hook "posts_orderby" in order to override the orderby settings set from the post type archive.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/sort-order-in-german-language/#post-919924

Relevant Documentation:

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by rolandD-3 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#918183

I am trying to: sort by string

Link to a page where the issue can be seen: sorry, local host

I expected to see: Items sorted like this:
1: Pöschl
2: Pohl

Instead, I got:
1: Pohl
2: Pöschl

It's a problem with the german umlauts. Often they are arranged after every other letter (x, y, z, ä, ö, ü, ß).
But to sort them the correct way you must handle them as they where translated like this:
ä = ae
ö = oe
ü = ue
ß = ss

It would be great if it were possible to sort by post slugs instead of post titles. Since German umlauts are rarely used in URLs, WordPress is so intelligent and generates correctly translated post slugs, i.e. the title "Pöschl" would result in the slug "poeschl".

So if I could sort by post slug the output of the items would be in the correct order 🙂

Regards,
Roland

#918261

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I would like to know, do you want to add sortable column for post slug - if yes, I just checked and added the sortable column for post slug and I can see its working fine.

If this is not your case - could you please tell me where exactly you want to apply sorting?

#918371
screenshot.jpg

Hello, no, I don't want to sort a column (what column?), I want to sort the listing of posts. You can adjust this in the general settings for view and for WordPress archives (please see attached screenshot, Beitragstitel = Post title). At the moment the output of archive listings is in the wrong order.

As far as I can see you can sort by post title, post date, post id, post author, post type, sort order in the menu, random order and by custom fields, but not by post slug.

Regards,
Roland

#919337

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - sorry for late reply.

Ok - I think we can override the order using the view's hook wpv_filter_query .

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

If you do not know how to use it - I would like to give a try and check if that works for you. For that I need access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#919924

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see you have post type archive page on which you want to display the correct order by post slug.

I've added following code to your current theme's functions.php file:

add_filter('posts_orderby', 'orderby_custom_callback', 10, 2);
function orderby_custom_callback($orderby_statement, $wp_query) {
	global  $wpdb;
	# Verify correct post type, or any other query variable
	if ($wp_query->get("post_type") === "autoren") {
				
		# In this trivial example add a reverse menu order sort
		return  $wpdb->prefix ."posts.post_name ASC";
		
	} else {
		# Use provided statement instead 
		return $orderby_statement;
	}
}

I can see now 6th and 7th entries are displayed as per your requirement. Could you please confirm.
=> hidden link

#920165

Thank you so much, perfect solution.

#920168

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It looks like you mark resolved ticket with wrong feedback and status, would you mind to resolve ticket with happy face 🙂

#920171

You have solved the problem perfectly.