1

I limit the search to post type in wp default search engine by adding a hidden field.

<input type="hidden" name="post_type" value="books" />

But I got a problem when the search string that have apostrophes in it. For example, I got a post called 'Adam's Apple', when I enter exactly 'Adam's Apple' in search input, no post was found. But when I enter ' Adam' ' (with apostrophes bit without the 's'), the post was found. But not found again if I enter 'Adam's' .

I tried it in normal post with same post's name and without limit to post type, everything working fine.

So obviously the apostrophes is the cause of this problem.

Any idea how I can fix it?

  • The part of the SQL related to post type has no relation to the search part of the query. But if you're convinced something's awry you can use this gist to show you the SQL being run: gist.github.com/stephenharris/5232517. But I would just double check you have a 'books' post called Adam's Apple and that you mean 'books' as opposed to 'book' :). – Stephen Harris Aug 4 '13 at 0:33
  • I also think so. But is there any way to change the sql for searching for the post type? – ron_dev Aug 5 '13 at 17:41

Your Answer

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

Browse other questions tagged or ask your own question.