function search_filter($query) {
if ($query->is_search) {
$query->set('post_type', 'page');
$query->set('post_parent', 1077);
}
return $query;
}
add_filter('pre_get_posts', 'search_filter');
function custom_search_redirect() {
global $wp_rewrite;
if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {
return;
}
$search_base = $wp_rewrite->search_base;
if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
wp_redirect(home_url("/docs/api/" . urlencode(get_query_var('s'))));
exit();
}
}
add_action('template_redirect', 'custom_search_redirect');