WordPress OpenSearch, v1.0
Monday, August 1st, 2005

WordPress OpenSearch, v1.0

The OpenSearch API provides a flexible common standard for XML-powered searches. I spent a bit of time this evening putting together a set of PHP files wrapping WordPress 1.5‘s search functionality. This code should be generic enough to allow anyone to quickly add OpenSearch RSS feed functionality to a WordPress 1.5 site.

For a version of this plugin which supports WordPress 2.0, please use WordPress OpenSearch 1.1.

The source is freely available for download here.

Here are six quick steps to getting your WordPress blog running an OpenSearch RSS feed:

Step 1
Download the WordPress OpenSearch code.

Step 2
Unpack the tgz contents into some directory under your wordpress installation. I chose /wp-content/code-plugins/wp-opensearch/. The “code-plugins” part isn’t strictly necessary; that’s just where I happened to put the files, as I didn’t feel right putting them in the plugins/ directory without first figuring out how to integrate the on/off switch with the WordPress admin interface. The php files do have relative require statements which access WordPress’s wp-blog-header.php, so being 3 directories down is important (unless you want to go to the small effort of changing the “../../..” values to reflect your directory structure).

Step 3
Replace logo.gif with your own 64 x 64 pixel image.

Step 4
Open up description.php and change whatever you like. Many values have been prefilled for your convenience. The ones you should be sure to replace are the tags, sample search, and my name and email address, unless you feel like making me more popular than I should be.

Step 5
Edit your .htaccess file so that the paths hardcoded in the PHP files will match up with the actual file locations on your site. Here’s a snippet from my .htaccess file, as an example. Be sure to add this after the line containing “# END WordPress”, or WordPress will overwrite your changes the next time you add a new page.

# BEGIN OpenSearch

<IfModule mod_rewrite.c>
RewriteRule ^os-query?(.*)$ /wb/wp-content/code-plugins/wp-opensearch/wp-opensearch.php?$1 [QSA,L]
RewriteRule ^os-description$ /wb/wp-content/code-plugins/wp-opensearch/description.php [QSA,L]
RewriteRule ^os-logo.gif$ /wb/wp-content/code-plugins/wp-opensearch/logo.gif [QSA,L]

#END OpenSearch

Step 6
At this point, you should be ready to use your new OpenSearch RSS feed. Head over to a9.com and add it to your columns. They have preview functionality which lets you debug any problems you hadn’t noticed before.

The API is: /os-query?s={searchTerms}&itemstart={startIndex}&itempage={startPage}&itemlimit={count}

6 Responses to “WordPress OpenSearch, v1.0”

  1. DeWitt Clinton Says:

    Very, very cool. And it will definitely be mentioned on the A9 Developer Blog as soon as I have a chance to update it in the morning.

    Do you know if the .htaccess file gets completely rewritten every time the WordPress settings for the permanent links are changed and/or a new page is added? That might be problematic…

    I’m going to install this on the A9 Dev Blog and on unto.net, too.


  2. Chris Says:

    Dealing with the .htaccess file getting rewritten everytime things change caused me no end of grief when trying to set up the Williamsburger Maps section of the site until I figured out that only the following part gets rewritten:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^archives/([^/]+)/trackback/?$ /wb/index.php?name=$1&tb=1 [QSA,L]
    # END WordPress

    Anything you add after the "# END WordPress" is maintained through the rewrites without alteration. I’ve updated the posting and the README in the tgz to reflect this information.

  3. inkdroid » A Tale of Two Searches Says:

    […] Yeah, that’s an ISBN and a ZIP code. Oh, and I installed Chris Fairbanks’ nice OpenSearch/WordPress plugin in like 5 minutes. Here’s an example: […]

  4. Anas M. Nebuchadnezzar XXXVII » OpenSearch now supported Says:

    […] That applies to me. I use two different searches. one for my blog, and another for Mycyclopedia. I read through the spec, and decided that I really wanted to implement this. Then I googled. It seems that Williamsburger beat me to it. Granted, his version only supports version 1.0, and I’ll probably end up writing my own anyway, but in the meantime you can go to A9 and add my column, or if you have your own consumer, view my Description document at: http://www.kronkltd.net/wp/os-description […]

  5. Antonio Van Helsing Says:

    Fantastic job! Great plugin! Looking forward to getting a newer update to OpenSearch v1.1. Once again, thanks for this plugin. It’s been implemented on http://www.aplaza.net/department-store/

  6. James E. Robinson, III Says:

    I documented what needs patching for WordPress 2.0 compatability here:

    Thanks for a useful plugin.

Leave a Reply