WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to find way to enable automatic search in WP. For example, I have a page mysite.com/some-thing. Within that webpage, I also want to display the content of the page mysite.com/?=some+thing. I don't want to use an iframe because I want the content of the second page (the search page) to be in the HTML source code of the first page.

Is this possible to achieve? I'm thinking about using WP web scraper plugin, but it is difficult to implement the selector :-(

Does anyone have any advice?

share|improve this question
up vote 1 down vote accepted

something like this in your page template, ideally after endwhile (if any)

$theQuery = strtolower(trim(get_the_title()));
$args = ('s='.$theQuery .'&showposts=5');
$search_query = new WP_Query($args);
if ($search_query->have_posts()) :
    while ($search_query->have_posts()) : 

        //do your stuff

share|improve this answer
Hi Gembel. Thank you very much for your great codes, but i'm haven't been able to use it. Could you fill-in a sample example in do your stuff section. Since i'm not quite sure what variable is the search content stored in. – Pam Apple Jun 19 '12 at 11:04
Okay, i have know how to use it now. Thanks. I could not use it because the post i was testing have no search result – Pam Apple Jun 19 '12 at 11:28
theQuery take page title, you can change $theQuery = 'a'; as a test to see the codes work – Gembel Intelek Jun 19 '12 at 11:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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