Note: this is one of a series of posts about the creation of the King Design web site.
One of the great benefits of using WordPress (or any CMS) to manage your web site is built in search capability. No matter how well you think you’ve structured your site, your site visitors will amaze you with creative ways to avoid finding the information you’ve tried to make available to them. Having search capabilities is one way to enable your visitors to get directly to what they are looking for.
WordPress provides searching for posts in the default configuration, but doesn’t support searching pages. I use pages for most a good deal of my site content, so it was important to me to have that content searchable as well. All it required was a little code change in wp-includes/classes.php (around line 490):
if (is_page()) {
$where .= ' AND (post_status = "static"';
} else {
$where .= ' AND (post_status = "publish"';
}
// Get private posts
if (isset($user_ID) && ('' != intval($user_ID)))
$where .= " OR post_author = $user_ID
AND post_status != 'draft'
AND post_status != 'static')";
else
$where .= ')';
becomes:
if (empty($_GET["s"])) {
if (is_page()) {
$where .= ' AND (post_status = "static"';
} else {
$where .= ' AND (post_status = "publish"';
}
// Get private posts
if (isset($user_ID) && ('' != intval($user_ID)))
$where .= " OR post_author = $user_ID
AND post_status != 'draft'
AND post_status != 'static')";
else
$where .= ')';
}
else {
$where .= ' AND
(post_status = "publish"
OR post_status = "static")';
}
(Note: Yes I asked Matt if this is a feature that would be good to include in the main codeline – the answer was no.)
I’ve added some additional code to present my search results grouped by type (Pages, FAQs and News) and also added options to search only FAQs and search only News. I’m not completely satisfied with the current implementation, but it was workable enough for an initial release of the site.
Currently, the Forums and the Tasks and Tasks Jr. documentation is not included in the main search, which is something I’ll likely work on over time. PunBB has its own search capabilities (that are frankly superior to the current WordPress capabilities), but it would be nice to integrate forum search results into the main search results. Since the Tasks and Tasks Jr. documentation is static HTML (created with PHP Doc System, I’ll need to integrate an additional system (likely PhpDig) to add search capabilities to that content. I tried an initial implementation when I was still developing the site, but never got it working as I wanted to.
I realize that Google (and probably others) provide other solutions, but I’d really like to keep the site interface consistent and Google doesn’t always have a current index of all of the content on a site. Perhaps there are other solutions I’m overlooking (comments are open).
This post is part of the following projects: Tasks Pro™, PHP Doc System. View the project timelines for more context on this post.
The WP search doesn’t include pages? Ug, that doesn’t make any sense. Deciding to specifically exclude that feature seems completely counterintuitive.
I have to admit I’m surprised that searching pages wouldn’t be considered important enough for future WP versions (I assume that’s what you meant by codeline).
When someone goes to a site and uses the search function, I think they are assuming that the search will check every potential location, whether that be post or page. From the user’s perspective, I think searching pages would be important.
I know there has been some talk of trying to improve the searching in WP, but I don’t know if that is planned for a “soon” release or a “future” release.
With the current search results interface, including pages would make no sense. Obviously it needs a different interface.
The code in the post has introduced a parse error into your RSS feed.
I know, I’m not sure the best way to “fix” it.
Upgraded to WordPress 1.5+
I’ve finally upgraded to WordPress 1.5 (plus a few patches). Would you believe that I’d still been running 1.0.1 (with a few security fixes)? I never upgraded to 1.2.x because of the slashes bug, so it’s nice to be current again.
A few notes:
…
[…] search the entire site is something I’ve wanted for a long time. I’ve said it before, search is important. I’ve also added links at the bottom of the search results page to allow you to do your […]