This depends on which collation you’ve got in your database. (So the sorting is usually done by sending a parameter (ORDER BY) with the request to the database.
Note that it’s not totally trivial to change the collation. If you just change the collation setting for a database, this will affect only tables that are created afterwards. Google for more details.
Hmm, but we have utf8mb4 as collation as default for everything in the database which seem to be recommended.
We used this snippet found here https://www.relevanssi.com/user-manual/relevanssi_hits_filter.
add_filter('relevanssi_modify_wp_query', 'rlv_sort_by_title');
function rlv_sort_by_title($q) {
$q->set('orderby', 'post_title');
$q->set('order', 'asc');
return $q;
}
Thanks again for helping!
If you use utf8mb4 as the encoding, then try to use utf8mb4_swedish_ci
as the collation.
Actually, database collation probably doesn’t affect the sorting of results, because Relevanssi fetches the posts from the database in relevancy order, then resorts them in PHP if some other sorting is required.
Relevanssi uses strcmp()
to sort the results and the strings are converted to uppercase with mb_strtoupper()
first.
I just tested this on my computer, and the sorting method Relevanssi uses sorts “åland” after “zeta”, as it should.
However, I don’t think that list has anything to do with Relevanssi. It’s not a search result – what’s the search term? Looks like it’s something generated by Search & Filter, and I can’t vouch for how S&F does the sorting. Perhaps it uses a different method that doesn’t understand the intricacies of Swedish language?
Now it works!
I got it to list the posts in the right order now. I noticed that in the WordPress admin all posts were in wrong order also, hence nothing wrong or associated with Relevanssi I think.
I installed PhpMyAdmin on the server and then inside PhpMyAdmin I found in the settings that I could change the database collation. Which I used to try to change the collation from utf8mb4 to utf8mb4_swedish_ci.
But because I am running MySQL 5.7 it has strict mode activated and I got error messages when I tried to change the collation inside PhpMyAdmin. When I had disabled strict mode then I was able to change the collation from utf8mb4 to utf8mb4_swedish_ci.
Thanks Tor-Bjorn Fjellner and Mikko Saari for pointing me in the right direction!