[wp-trac] [WordPress Trac] #21803: Add filter to make extending searching easier
WordPress Trac
wp-trac at lists.automattic.com
Wed Sep 5 13:50:13 UTC 2012
#21803: Add filter to make extending searching easier
-------------------------+-------------------------------------
Reporter: mark8barnes | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.4
Severity: normal | Keywords: has-patch needs-testing
-------------------------+-------------------------------------
I'm using custom post types, and want to extend the search function so
more than post_title and post_content are searched. It is currently
possible to filter `posts_search` but that returns a string such as ` AND
(((wp_posts.post_title LIKE '%test%') OR (wp_posts.post_content LIKE
'%test%'))) `. This string then has to be rather messily manipulated via
`preg_replace` or `str_replace`.
It would be more useful if we could filter a list of fields to be added to
the search criteria, so that we could add a function to extend or change
the criteria:
{{{
add_filter ('search_fields', 'my_custom_search_fields');
function my_custom_search_fields ($fields) {
global $wpdb;
$fields[] = "{$wpdb->prefix}posts.post_excerpt";
return $fields;
}
}}}
The attached patch implements that filter.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21803>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list