Use pre_get_posts
to modify the query object before the query has run. – https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-1,-1347' );
}
else if ($query->is_search) {
$query->set( 's', 'stackoverflow' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );