Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Improve WordPress Search WordPress

  • SOLVED

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 [[LINK href="http://www.relevanssi.com/"]]Relevannsi[[/LINK]] and [[LINK href="https://core.sproutventure.com/projects/show/search-everything"]]Search Everything[[/LINK]], but neither have worked.

Here is the search I am trying to improve: http://visitprineville.org/category/members/

Any suggestions would be appreciated. Thanks!

Answers (3)

2011-09-25

Pippin Williamson answers:

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' );

2011-09-25

Julio Potier answers:

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

2011-09-25

Ivaylo Draganov answers:

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' );