Let’s if it helps you. Instead of adding a custom query var if we can use directly from url that might solve the issu. First make post_parent
loadable from url.
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' );
Now focus on the filter:
function admin_page_filter_parentpages() {
global $wpdb;
if (isset($_GET['post_type']) && $_GET['post_type'] == 'books') {
$sql = "SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_type="books" AND post_parent = 0 AND post_status="publish" ORDER BY post_title";
$parent_pages = $wpdb->get_results($sql, OBJECT_K);
$select="
<select name="post_parent">
<option value="">Parent Pages</option>";
$current = isset($_GET['post_parent']) ? $_GET['post_parent'] : '';
foreach ($parent_pages as $page) {
$select .= sprintf('<option value="%s"%s>%s</option>', $page->ID, $page->ID == $current ? ' selected="selected"' : '', $page->post_title);
}
$select .= '
</select>';
echo $select;
} else {
return;
}
}
add_action( 'restrict_manage_posts', 'admin_page_filter_parentpages' );
Give it a try and let me know.