Search Post Excerpt
-
The optional excerpt is not searched by default or at all.
I could write a plugin that does this I suppose, but its one of those things that one would assume got searched.Its trivial to add, you just change three lines in wp-includes/classes.php:
from:
if (!$q['sentence']) {
$s_array = explode(' ',$q['s']);
$q['search_terms'] = $s_array;
$search .= '((post_title LIKE ''.$n.$s_array[0].$n.'') OR (post_content LIKE ''.$n.$s_array[0].$n.''))';
for ( $i = 1; $i < count($s_array); $i = $i + 1) {
$search .= ' AND ((post_title LIKE ''.$n.$s_array[$i].$n.'') OR (post_content LIKE ''.$n.$s_array[$i].$n.''))';
}
$search .= ' OR (post_title LIKE ''.$n.$q['s'].$n.'') OR (post_content LIKE ''.$n.$q['s'].$n.'')';
$search .= ')';
} else {
$search = ' AND ((post_title LIKE ''.$n.$q['s'].$n.'') OR (post_content LIKE ''.$n.$q['s'].$n.''))';
}
to
if (!$q['sentence']) {
$s_array = explode(' ',$q['s']);
$q['search_terms'] = $s_array;
$search .= '((post_title LIKE ''.$n.$s_array[0].$n.'') OR (post_content LIKE ''.$n.$s_array[0].$n.''))';
for ( $i = 1; $i < count($s_array); $i = $i + 1) {
$search .= ' AND ((post_title LIKE ''.$n.$s_array[$i].$n.'') OR (post_content LIKE ''.$n.$s_array[$i].$n.'') OR (post_excerpt LIKE ''.$n.$s_array[$i].$n.''))';
}
$search .= ' OR (post_title LIKE ''.$n.$q['s'].$n.'') OR (post_content LIKE ''.$n.$q['s'].$n.'') OR (post_excerpt LIKE ''.$n.$q['s'].$n.'')';
$search .= ')';
} else {
$search = ' AND ((post_title LIKE ''.$n.$q['s'].$n.'') OR (post_content LIKE ''.$n.$q['s'].$n.'') OR (post_excerpt LIKE ''.$n.$q['s'].$n.''))';
}
Give me a good reason why WP shouldn’t search the excerpt by default?(if its not there it just won’t be searched)
- The topic ‘Search Post Excerpt’ is closed to new replies.