I want to improve my default Wordpress search query and add COLLATE utf8_bin. What is the best way to do this action? Should I edit wp-includes/query.php or manipulate with functions.php file from themes folder?

  • I told you - never ever touch the core. First, you will lose all your changes upon update. Secondly, with a very high probability, you will crush some functionality of WordPress. After your previous question, I tried to analyze by Xdebug the code related to the main WordPress query, and understand why COLLATE does not work. With no success so far, hopefully will find enough time in the next few days. Code is complicated there, with two passes in respect to caching plugins, with many conditions involved. Feb 22, 2018 at 22:15
  • And I analyze code of the core not to edit it, by to find a proper hook usage which will solve the task. Feb 22, 2018 at 22:18

1 Answer 1


You should add the following code to the functions.php of your theme (and it is better to make all modifications in child theme):

add_filter( 'posts_search' , 'posts_search' );
function posts_search( $search ) {
    $search = str_replace( 'LIKE', 'COLLATE utf8_bin LIKE', $search );

    return $search;

It works. You can check it on my test site:


returns one post, but


returns nothing.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.