Searching With Apostrophe

I’m having trouble with my custom theme’s search function. I have a number of posts with apostrophes in the title. For example, McDonald's.

However, when I try searching say McDonalds, the post won’t return in the search results.

Read More

How can I go about making sure that McDonald's would return in the result even if the user didn’t include the apostrophe.

Related posts

1 comment

  1. Your question isn’t much of a WordPress related question, more like a MySQL question.
    But I have sort of a solution in my head:

    You could go with a custom query and a replace on the apostrophe:

    SELECT * FROM `table`
    WHERE REPLACE( `column`, "'", "") LIKE REPLACE( 'string', "'", "" )
    

    For a combined search:

    SELECT *, REPLACE( `column`, "'", "" ) AS `custom`
    WHERE `column` LIKE 'string'
    OR `custom` LIKE 'string'
    

    It isn’t worlds most beautiful solution, but you could give it a shot.

Comments are closed.