One way to achieve this is by looping through the parent pages and fetching their respective children pages ids.
The resulting arrays can then be merged and used in the 'post__not_in'
variable.
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;
}
}
Related Posts:
- Restrict admin access to certain pages for certain users
- Show different badge based upon the user role
- List all private pages user has access rights to read
- Role can edit just one page [closed]
- How do I count the number of pages a user has seen on my site, and force them to log in after a certain amount
- Allowing user to edit only certain pages
- Check if is on child-page of a particular page
- Check IF is a “single product page” and Check the “role” for a Redirect
- A check for if is parent page, if has children, if has grandchildren
- Create a “Dummy” parent page for a hierarchy in page listing?
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- Hide Admin Menu for Specific User ID who has administrator Role
- Allow only new sub-pages to be created
- Is there a default template file for child pages / subpages?
- Get Permalink for the top level parent of child pages
- Some pages are missing from the Parent Page select in the Editor
- How to display list of child pages of parent page in wordpress?
- How to count current user’s pages?
- Restrict acceess of a page in backend
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- How to display page title+link of page created by user
- Only allow new subpages to be created
- Associate Page with User
- How to customize wp_signon()
- Can I create users that have access to *some* other users posts instead of all other users posts?
- Show child pages when on a child page
- User capability of create page/new page
- select a private page as parent for another private page
- WordPress pages with hierarchy
- Managing Users and Creating Groups [closed]
- Personal page for every user (not just authors)
- load common thank you template with different content for different pages
- How to disable a specific page for a specific user
- List child pages by slug not ID?
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Adding New Users to Your WordPress Site for edditign only one page
- How to create a page that lists all the experts(Users with same access permission as author)?
- Problem with automatic role change through cron job
- How can I allow an User to publish only 5 posts per month?
- get_pages() & “child_of”
- Restricting Pages based on Hierarchy and User Role
- Create custom post with custom user rules
- Where are $current_user->allcaps set?
- Removing Parent Page URL While Keeping the Navigation Intact
- Organizing Your Pages
- Custom page template for multiple pages
- Can a user find a child page?
- Display child pages in sidebar of parent page in wordpress
- Display child pages in a parent page? [closed]
- Redirect page to default subpage
- List all posts with the parent or grandparent of a page with a specified ID
- Page access only from a specific page in wordpress website
- Can I “protect” a page with a form asking for an email address?
- Restrict the list of parent pages to only those which are created by current user
- Allow admins to login as other users
- Can I Create a Second Admin Level User Role?
- Redirect admin 403 “Cheatin uh?” admin pages
- Keep page hierarchy in wp_list_pages, even if on a child or grandchild
- Allow a user to edit their own page and profile only
- Custom page only editable by one user
- One author not showing in Author drop down list while editing page
- How to control display of page lists on sidebar that doesn’t have childrens
- Check if page has subpages
- Exclude child pages args array
- Author page like wordpress answers
- WordPress user role with create user capability?
- Search anything from a Child and Sub-Pages of their Parent page
- Custom user tables not working after migration
- Update user role for expired membership
- When I enter password, I’m redirected to the WordPress login form
- Every change made by “Author” role is going to “pending review”
- How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?
- Return true if parent page id matches
- Not allow add New Page for role ‘editor’
- If page or sub page not working as expected
- How to use wp_dropdown_pages or wp_list_pages to accomplish a menu like this?
- Custom User Role: Can Edit Own Page, Cannot Create New
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Restrict Access to the User Profile
- How to limit the pages shown in the page manager to those created by the logged in user?
- Display inner pages like posts.[Like how post excerpt works]
- Childpage title + content on Parent Page
- Pages redirecting to homepage
- Firing page_publish where page is child page
- How to finish this loop?
- Add role and edit page capabilities
- disable trashability for certain pages
- Standard way of creating profile pages with custom content for each user?
- displaying child pages in columns when on a parent page
- How to make in post Parent page children page list nummbered
- Woocommerce – Making product pages child of shop
- each user having category with their name and can add sub categories post in that category
- Limit user access to installing/configuring a plugin?
- List of pages – AJAX load more
- Forbid certain users to access a specific page
- file upload user profile
- How to give different user access to different people?
- User profile in front-end