WordPress – wpdb ->get_results – wrong encoding

I have a WordPress installation and a custom table in the WP database called c_schools. Inside my custom template page, I do the following query:

$schools = $wpdb->get_results("SELECT school_id, school_name FROM c_schools ORDER BY school_id");

and then write the results as a HTML list.

Read More

The school names contain czech symbols, such as ě, š, which are not displayed properly.

The encoding of the whole database (including the custom table) is utf8, the collation is utf8_general_ci.

When I run the query in the mysql application in a terminal via a putty session, all characters display fine.

The rest of the page displays fine, including the name of the page in the menu, which contains these symbols as well and (I believe) is loaded from the same database.

When examining the response headers via firebug, I found the following content-type:

Content-Type    text/html; charset=UTF-8

So it really seems to be an error in the PHP script on the server side, perhaps the wpdb is not configured properly?

What am I doing wrong?


I used the advice found on this SO page and verified that the encodings of the database, table and the column are all utf8.


I have found the following lines in my wp-config.php, which seem correct.

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

The following meta tag is present in the head part of the page.

<meta charset="UTF-8" />

Related posts

Leave a Reply