您可以使用pre_get_posts
过滤器挂钩并设置post__not_in
查询ex的参数:
function exclude_from_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$query->set(\'post__not_in\', array(40, 9) ); // id of page or post
}
return $query;
}
add_filter( \'pre_get_posts\', \'exclude_from_search_filter\' );