我唯一能找到答案的方法是建立一个ID列表,如下所示:
/*
* Hide some pages from search results
*/
function SearchFilter($query) {
if ($query->is_search) {
$exclude = \'18,20,12,22,132,76,81,78,84,91\';
// Get all children of #18
$pages = get_pages(\'post_parent=18\');
foreach($pages as $child) {
$exclude .= "," . $child->ID;
}
$query->set(\'post__not_in\', explode(",", $exclude));
}
return $query;
}
add_filter(\'pre_get_posts\',\'SearchFilter\');
您可以使用任何WP\\u查询参数来执行类似的操作(例如构建要包含的ID列表)。