好的,团队,我明白了,这很简单。使用get\\u page\\u by\\u path检索页面并获取其slug,然后将其作为一个数组对象传递,该数组对象将转换为一个post id数组。由于主页没有slug,我不得不使用get\\u选项获取首页的id并将其推送到数组中。
function hide_pages_in_admin($query)
{
// Create array of all the slugs you wanna hide
$hidden_slugs = array(\'about-us\', \'contact\', \'404\');
// Loop through slugs & pass each slug as page path value
foreach ($hidden_slugs as $hidden) {
$hidden_slugs[] = get_page_by_path($hidden)->ID;
// In case you need to hide the home page too
$hidden_IDs[] += get_option(\'page_on_front\');
}
// Select the user type to hide pages from
if (current_user_can(\'editor\')) {
// Pass the array as value to the query vars filter
$query->query_vars[\'post__not_in\'] = $hidden_slugs;
}
}
add_filter(\'parse_query\', \'hide_pages_in_admin\');