I've created a custom filtering facility for a front end search, which also includes a specific user group.
To add the function to the search I have used
add_filter('pre_get_posts','my_filter_the_search',10,1);
function my_filter_the_search($query){
$post_type = filter_input(INPUT_GET, 'post_type', FILTER_SANITIZE_STRING);
if($post_type == 'document'):
add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
//Get array of slugs of checked terms
$terms = (array) $_GET['post_type'];
//Tax_query array
$tax_query = array(array(
'taxonomy' => 'access',
'terms' => 'basic-user',
'field' => 'slug',
));
//Tell the query to filter by tax
$query->set('tax_query', $tax_query);
return $query;
endif;
}
This appears to be effecting the listing of a custom post type in the backend.
How do I only use this for the front end of the site?