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.
Jun 12, 2005
Weblog Tools Collection » WP Hack: Search posts and pages
Denis de Bernardy
Jun 12, 2005
http://randomfrequency.net/wordpress/search-pages/
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.
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.’
Jun 13, 2005
freshlabs – Wordpress Pages durchsuchen
vedjen
Feb 10, 2006
Thanks for the hack! Just what I was looking for.
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…