A client has a website with a user directory and they'd like the user's author pages to be excluded from the site search so that if a user searches for "smith" they wouldn't get pages with "smith" as well as a link to John Smith's user profile.
I've added the following code to the functions file which is said to restrict search results to just posts and pages:
add_filter('pre_get_posts', 'SearchFilter');
function SearchFilter($query){
if($query->is_search){
$query->set('post_type', array('post', 'page'));
}
return $query;
}
User profiles are still showing up in the search results, though. I've also echoed the global $wp_query and see that the post types are being set, but the author pages with a post_type of user (which isn't an actual post type) are still being displayed.
You can see in this image that post_type is set to posts and pages:
Here, though, you can see that a post_type of user is still being pulled into the search results:
How should I go about excluding the users from the search?
Update: I've used the below code to output all of the registered post types to make sure that "user" isn't in the list.
add_action('init', 'update_my_custom_type', 99);
function update_my_custom_type(){
global $wp_post_types;
print_r($wp_post_types);
}