实现这一点的一种方法是通过循环父页面并获取其各自的子页面ID。
然后,可以合并生成的数组并将其用于\'post__not_in\'
变量
add_filter( \'parse_query\' , \'exclude_pages_from_admin\' );
function exclude_pages_from_admin( $query ) {
global $pagenow,$post_type;
$pages = array(\'1\',\'2\',\'3\');
foreach ( $pages as $parent_page ) {
$args = array(
\'post_type\' => \'page\',
\'post_parent\' => $parent_page,
\'fields\' => \'ids\',
);
$children = new WP_Query( $args );
$pages = array_merge( $pages, $children );
}
if ( is_admin() && $pagenow == \'edit.php\' && $post_type == \'page\' && current_user_can(\'custom_role\') ) {
$query->query_vars[\'post__not_in\'] = $pages;
}
}