I added the following to my functions.php:
add_action('pre_get_posts', 'keyl_get_emp_posts');
function keyl_get_emp_posts($query) {
if ($query->is_main_query())
$query->set('post_type', 'employee');
}
and so far it’s effectively filtering out the search results. The default widgets Recent Posts and Recent Comments aren’t budging, though. What gives?
pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc).
But be aware, that code you added there will change the query for ALL your main queries. So if you go to another post type archives (categories, etc) you will be modifying the query to get the post_type = employee
Both the “Recents Posts” widget and the “Recent Comments” widget provide a filter that you can use to alter the query, and they both conveniently take the same argument.
That will alter the widgets every time they run so if you need the widgets to function in multiple contexts you will need something more complicated.