WordPress Query £ signs failure

I have code that takes the name of a term and pulls in a post of a custom post type of the same name. This works well. Except when a £ character is in the title.

e.g. pseudocode

Read More
$q = new WP_Query (array( 'name' => "Insurance Rating £1K"));
if($q->have_posts()){
    // expected path of logic flow
} else {
    // nothing was found =s
}

This post does indeed exist, yet it is not found, and this problem only affects cases with a ‘£’ character in the title. Since WordPress already sanitizes the titles etc, what is happening? Why does this not work?

edit:

This is a general case, not specific to any codebase of mine. I want to know why this happens and how to avoid it, the codebase this first arose in is irrelevant. So I dont need an alternative solution, as I’m looking for Why it happened

edit 2:

The database tables are using utf8_general_ci encoding.

The £ character is also being saved as is, not as a html entity, here’s a screenshot from phpmyadmin:

Database row

Related posts

Leave a Reply

1 comment

  1. What encoding is your PHP file in, and does it match the encoding of the database? They need to match for this to work. (Check your IDE or this link provided by @Tom)

    Failing that, make sure that the character isn’t a £ entity instead of the literal character.