Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to limit the posts and pages listed in the admin area to certain roles. There are plugins out there that can do some of what I need but they aren't granular enough for my needs.

For example I have a 'Advice editor' role and I want to limit them to seeing and editing the 'Advice' pages (and by extension any categories I might wish to add).

I have this cobbled together from various posts. It works but I can't get the list to include the parent and all children (it is either the parent or the children but not both). This maybe more of a WP_Query question or there maybe a different way to do it:

// http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/
function appthemes_check_user_role( $role, $user_id = null ) {

if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
    $user = wp_get_current_user();

if ( empty( $user ) )
return false;

return in_array( $role, (array) $user->roles );

// http://www.johnparris.com/how-to-hide-pages-in-the-wordpress-admin/
function jp_exclude_pages_from_admin($query) {

if (!is_admin()) {
    return $query;

global $pagenow, $post_type;

if (appthemes_check_user_role("Advice Editors")) {

 if ($pagenow == 'edit.php' && $post_type == 'page') {

    //$query->query_vars['post_parent'] = 7;
    //$query->query_vars['post__in'] = array( '7' ); // Enter your page IDs here
    //$query->set('post__in', array('7'));
    $query->set('post_parent__in', array('7'));



add_filter( 'parse_query', 'jp_exclude_pages_from_admin' );

I have come across the Press Permit plugin which can do this but it is a paid-for plugin and I'd like to understand this myself anyway.

EDIT: I appreciate I can just put array the post_ids to include but I want to limit this by parent page and its children programmatically, in case future children pages are added (IDs are too vague in this case).

Thanks in advance

share|improve this question
Went with the Press Permit premium plugin (presspermit.com) to do this, which works well. –  Dave McCourt Mar 11 at 16:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.