Skip to main content
added closing bracket and re-indented main function set
Source Link
CK MacLeod
  • 1.9k
  • 1
  • 12
  • 15

So following from the comment discussion, a sufficient answer on another StackEx question goes like this:

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
}

The only part that's terribly important to us is the array of post IDS.

The problem is that a post on a given installation can have the identical slug, but will normally have a different ID.

So, what if we create an array of the to-be-excluded post slugs:

$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

This ought to work from installation to installation assuming identically slugged posts/pages:

add_filter( 'parse_query', 'exclude_pages_from_admin_by_slug' );

function exclude_pages_from_admin_by_slug( $query ) { 

    global $pagenow, $post_type;

    //set the array of to be excluded slugs
    $excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

    //get array of IDs from array of slugs
    foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

    }

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

        //exclude those IDs from query
        $query->query_vars['post__not_in'] = $excluded_IDs;

    }

}

Can't vouch for the entirety of the code from testing, and obviously it was meant to answer a different question. Since we don't have alternative code to go on, the only interest here is a model for deriving an array of to-be-excluded IDs and employing it.

So following from the comment discussion, a sufficient answer on another StackEx question goes like this:

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
}

The only part that's terribly important to us is the array of post IDS.

The problem is that a post on a given installation can have the identical slug, but will normally have a different ID.

So, what if we create an array of the to-be-excluded post slugs:

$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

This ought to work from installation to installation assuming identically slugged posts/pages:

add_filter( 'parse_query', 'exclude_pages_from_admin_by_slug' );

function exclude_pages_from_admin_by_slug( $query ) { 

global $pagenow, $post_type;

//set the array of to be excluded slugs
$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

//get array of IDs from array of slugs
foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

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

    //exclude those IDs from query
    $query->query_vars['post__not_in'] = $excluded_IDs;

}

Can't vouch for the entirety of the code from testing, and obviously it was meant to answer a different question. Since we don't have alternative code to go on, the only interest here is a model for deriving an array of to-be-excluded IDs and employing it.

So following from the comment discussion, a sufficient answer on another StackEx question goes like this:

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
}

The only part that's terribly important to us is the array of post IDS.

The problem is that a post on a given installation can have the identical slug, but will normally have a different ID.

So, what if we create an array of the to-be-excluded post slugs:

$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

This ought to work from installation to installation assuming identically slugged posts/pages:

add_filter( 'parse_query', 'exclude_pages_from_admin_by_slug' );

function exclude_pages_from_admin_by_slug( $query ) { 

    global $pagenow, $post_type;

    //set the array of to be excluded slugs
    $excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

    //get array of IDs from array of slugs
    foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

    }

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

        //exclude those IDs from query
        $query->query_vars['post__not_in'] = $excluded_IDs;

    }

}

Can't vouch for the entirety of the code from testing, and obviously it was meant to answer a different question. Since we don't have alternative code to go on, the only interest here is a model for deriving an array of to-be-excluded IDs and employing it.

Source Link
CK MacLeod
  • 1.9k
  • 1
  • 12
  • 15

So following from the comment discussion, a sufficient answer on another StackEx question goes like this:

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
}

The only part that's terribly important to us is the array of post IDS.

The problem is that a post on a given installation can have the identical slug, but will normally have a different ID.

So, what if we create an array of the to-be-excluded post slugs:

$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

This ought to work from installation to installation assuming identically slugged posts/pages:

add_filter( 'parse_query', 'exclude_pages_from_admin_by_slug' );

function exclude_pages_from_admin_by_slug( $query ) { 

global $pagenow, $post_type;

//set the array of to be excluded slugs
$excludeds = array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' );

//get array of IDs from array of slugs
foreach ( $excludeds as $excluded ) {

        $excluded_IDs[] = get_page_by_path( $excluded )->ID;

}

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

    //exclude those IDs from query
    $query->query_vars['post__not_in'] = $excluded_IDs;

}

Can't vouch for the entirety of the code from testing, and obviously it was meant to answer a different question. Since we don't have alternative code to go on, the only interest here is a model for deriving an array of to-be-excluded IDs and employing it.