Search is Important

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.