Want to filter only parent post in admin area

In addition to my previous answer add following code. It should work fine

add_filter( 'views_edit-books', 'add_filter_link' );
function add_filter_link( array $views ) {
    $url = add_query_arg( array('bfilter'=>'parents','post_parent'=>0,'post_type'=>'books'), 'edit.php' );
    $views[ 'post_parent' ] = sprintf(
        '<a href="%1$s"%2$s>%3$s</a>',
        esc_url( $url ),
        ( is_filter_active() ) ? ' class="current" aria-current="page"' : '',
        'Post Parents'
    );
    return $views;
}

function is_filter_active() {
    return (filter_input( INPUT_GET, 'bfilter' ) ==='parents');
}

if you already not used bellow code then add that too

function make_post_parent_public_qv() {
    global $pagenow;
    if ( is_admin() && $pagenow == 'edit.php' )
        $GLOBALS['wp']->add_query_var( 'post_parent' );
}
add_action( 'init', 'make_post_parent_public_qv' );

Leave a Comment