I'm in the process of building a Wordpress plugin. I wish to mimic WP's default search functionality but in the form of a 'live search'.

I have my JS setup to grab the query string (i.e what would be /?s=search-term) & am passing it via AJAX to my function. But now I have to process the query to get the list of posts & pages. But I've read that it's not right to simply use query_post from the WP documentation.

So my question is, what is the correct approach to yield the same search results as if the default search form was submitted?

Please can someone provide a code snippet or a link to a detailed article which clarifies this for me.

Thanks & please pardon my nativity!

1 Answer 1


Pass the 's' parameter to a new WP_Query object.

$mys = new WP_Query(
    's' => 'whatever',

That should duplicate the default search.

  • Well that was easier than I first thought! Thanks.
    – Sheixt
    Commented Nov 12, 2013 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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