WordPress search posts and pages hack

June 12, 2005 @ 7 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.

7 Comments → “WordPress search posts and pages hack”

  1. Jun 12, 2005


  2. Denis de Bernardy

    Jun 12, 2005


  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.


  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.’

  5. Jun 13, 2005


  6. vedjen

    Feb 10, 2006

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


  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…


Leave a Reply

Copyright © 2012 Homeland Stupidity.

Bad Behavior has blocked 3233 access attempts in the last 7 days.