WordPress search posts and pages hack

June 12, 2005 @ Michael Hampton7 Comments

This is a quick hack that lets the WordPress built-in search facility search posts and pages. By default, WordPress searches only posts. It was created against WordPress 1.5.1.2, but should work with previous versions if applied in the right place. Download the patch here.

If you can’t patch for some reason, you can apply the changes manually. Edit the wp-includes/classes.php file, and somewhere around line 500 you should see the following:

    if ($this->is_page) {
      $where .= ' AND (post_status = "static")';

Immediately after this, add these two lines:

    } elseif ($this->is_search) {
      $where .= ' AND (post_status = "publish" OR post_status = "static")';

This patch has been submitted for inclusion in a future version of WordPress.

Update: It seems this hack has been done before. My hack is a little cleaner, though. And someone else turned it into a plugin. Oh well, life goes on.

Article Series - WordPress Hacks

  1. WordPress sidebar login form hack
  2. WordPress search posts and pages hack
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

7 Comments → “WordPress search posts and pages hack”

  1. Jun 12, 2005

    Reply

  2. Denis de Bernardy

    Jun 12, 2005

    http://randomfrequency.net/wordpress/search-pages/

    Reply

  3. Michael Hampton

    Jun 12, 2005

    Great minds think alike, I guess. Doing it in a plugin is nice, but this really should be in WordPress in some form or another.

    Reply

  4. Denis de Bernardy

    Jun 13, 2005

    Agreed. But I recall this was discussed in the list at one point and rejected on grounds that were along the lines of: ‘wp is a blogware, not a cms, so it will remain a plugin.’

    Reply
  5. Jun 13, 2005

    Reply

  6. vedjen

    Feb 10, 2006

    Thanks for the hack! Just what I was looking for.

    Reply

  7. Steven

    Feb 25, 2007

    Wicked, the hack is also working for Wordpress MU 1.0! Go to wp-includes/query.php and search for:

    if ( $this->is_attachment ) {

    which should be on line 915 and add the code mentioned above.

    Funny though that this is still not a default option within Wordpress…

    Reply

Leave a Reply

Copyright © 2010 Homeland Stupidity.