1

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.

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

0

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.

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.