Fix sort/order with post_title for international characters

If you want to list your posts and order them by title, that is as simple as:

query_posts('orderby=title')

But if you are using international characters and/or another alphabet the default database settings may mess things up for you.

In Sweden for example, the last the letters in the alphabet are Å, Ä, Ö. So accordingly, posts with titles starting with those letters should come last in an ascending list, but by default ‘Å’ and ‘Ä’ will be considered as ‘A’ and ‘Ö’ as ‘O’ .

But there’s an easy fix for this. Simply change the collation of the post_title column.

Execute the following SQL query. Remember to back up your database before, just to be safe!

ALTER TABLE wp_posts CHANGE post_title post_title TEXT CHARACTER SET utf8 COLLATE utf8_swedish_ci;

This will give your post_title column a Swedish collation, so please change to your desired collation.

Advertisements
About

Web Developer @ Oakwood Creative - www.oakwood.se

Tagged with: , , ,
Posted in Intermediate
4 comments on “Fix sort/order with post_title for international characters
  1. Emil says:

    Bra att du tar upp det här problemet. För mig uppstår det när jag vill visa en länklista i bokstavsordning, med hjälp av WP-Render-Blogroll-Links.

    Kan du berätta vart man ska göra det du föreslår här ovan, för mig som inte är så hi på kodning…

  2. Vincent says:

    Hi Emil,

    As I mention in the post you have to alter the database table to make it work. The easiest way to this this is with an MySQL client or perhaps PhpMyAdmin. But you could also do it with code.

    But if you’re not an experienced programmer I would recommend using an MySQL client. There you could execute the query right away, or simply change the table settings through the interface.

  3. Anonymous says:

    […] fix, vet ikke om den funker 100%? Fix sort/order with post_title for international characters | WordPress Quick Tips __________________ Webdesign – logodesign – grafisk design – art direction & […]

  4. Rick says:

    Thanks for this. Solved my problems.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About

WordPress Quick Tips is a blog supplying great tips about WordPress.

We hope to create a great knowledge resource for WordPress developers as well as serving a reminder for all the forgetful ones.

The blog is created and run by Vincent of Oakwood Creative

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 120 other followers

%d bloggers like this: