WordPress search results on external page

I have a custom search engine on a non-wordpress page. This search engine searches a database for a city (specified by a text input) and then returns the relevant information about that city and displays it on the page.

What I want to do now, is to below those results, display the results of a wordpress search of the same term on a blog that resides on the same server/domain. So basically I want to show the same results that a wordpress search of that keyword would return, but I want to display them on a non-wordpress page, not in the blog’s theme.

Read More

What I have:

a variable holding a search term, the search term has already been shampooed and conditioned to be search engine friendly.

What I don’t want to do

  • I don’t want to use an iframe and have the blog template be displayed on the page.
  • I can’t have a secondary search box. I need to somehow use the value of the variable that I have, I can’t ask the user to submit a second form or anything.

My ideas so far

Is there a way to run the wordpress search function and grab the data that it returns? I’ve gotten as far as including wp_blog_header.php on my static page so that I can make use of the wordpress functions.

Or would it be better to write a function that duplicates what the wordpress search does on the wordpress databases, but returns the data in a way that I can use?

Or is there a different approach that I should take for this that I’ve overlooked? Thanks!

Related posts

Leave a Reply

1 comment

  1. You must first include the WordPress files

    <?php define('WP_USE_THEMES', false);
    require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
    

    then use query_posts and the loop

    query_posts('s='.keyword);
    while (have_posts()): the_post(); ?>
        <h2><?php the_title(); ?></h2>
        <?php the_excerpt(); ?>
        <p><a href="<?php the_permalink(); ?>">Read more...</a></p><?php
    endwhile;