$12
Improve WordPress Search
Hi, I am trying to improve the WordPress search to allow for a search of the custom post types. There is a custom post type called "members" that is not being searched by the current search function.
Users should be able to search the members directory by company titles or terms. Currently nothing is being pulled.
I have tried using Relevannsi and Search Everything, but neither have worked.
Here is the search I am trying to improve: http://visitprineville.org/category/members/
Any suggestions would be appreciated. Thanks!
Users should be able to search the members directory by company titles or terms. Currently nothing is being pulled.
I have tried using Relevannsi and Search Everything, but neither have worked.
Here is the search I am trying to improve: http://visitprineville.org/category/members/
Any suggestions would be appreciated. Thanks!
Auz Clement | 09/25/11 at 4:28pm
| Edit
(3) Possible Answers Submitted...
-

Last edited:
09/25/11
4:40pmPippin Williamson says:The first thing you can do is include the Members post type in the search query. It's excluded by default. To enable it, put this in your functions.php:
function add_members_to_search( $query ) {
if ( $query->is_search ) {
$query->set(
'post_type', array( 'post', 'page', 'members' ));
}
return $query;
}
add_filter( 'the_search_query', 'customSearch' );
-

Last edited:
09/25/11
4:47pmJulio Potier says:Hello
Check the codex : http://codex.wordpress.org/Function_Reference/register_post_type
and focus on "exclude_from_search"
Check your "register_post_type" in your plugin or functions.php (from theme)
See you -

Last edited:
09/25/11
5:19pmIvaylo Draganov says:Hi,
Try this code:
function include_custom_posts_in_search( $query ) {
if ( is_search() ) {
$query->set( 'post_type', array ( 'post', 'members' ) ); // array of post types to include
}
}
add_action( 'pre_get_posts', 'include_custom_posts_in_search' );
This question has expired.
Auz Clement voted on this question.
Current status of this question: Completed





