Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 down vote accepted

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

<?php 
$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()) : 
        $search_query->the_post();

        //do your stuff

    endwhile;
endif;
?>
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
add comment

Your Answer

 
discard

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.