add_filter('views_edit-page','addFilter');
function addFilter($views) {
global $wp_query;
$query = array(
'post_type' => 'page',
'post_status' => 'publish',
'post_parent' => 2795,
);
$result = new WP_Query($query);
$class = ($_GET['post_parent'] == 2795) ? ' class="current"' : '';
$views['publish_f'] = sprintf(__("<a href='%s'". $class .">". 'Post Parent = 2795' ." <span class='count'>(%d)</span></a>", 'brookdale' ), admin_url('edit.php?post_type=page&post_parent=2795'), $result->found_posts);
return $views;
}
I want to create filter for my Admin panel "Pages" tab that only shows pages that are children or grand-children or great-grand-children of the parent post. I currently have the tab showing, but when I click the filter it does not load the pages into the word press pages list. I have been trying to find documentation on this specific function for wordpress but it's a bit difficult to explain correctly in a google search.
add_filter('views_edit-page','addFilter');
function addFilter($views) {
global $wp_query;
$query = array(
'post_type' => 'page',
'post_status' => 'publish',
'post_parent' => 2795,
);
$result = new WP_Query($query);
$class = ($_GET['post_parent'] == 2795) ? ' class="current"' : '';
$views['publish_f'] = sprintf(__("<a href='%s'". $class .">". 'Post Parent = 2795' ." <span class='count'>(%d)</span></a>", 'brookdale' ), admin_url('edit.php?post_type=page&post_parent=2795'), $result->found_posts);
return $views;
}
I want to create filter for my Admin panel "Pages" tab that only shows pages that are children or grand-children or great-grand-children of the parent post. I currently have the tab showing, but when I click the filter it does not load the pages into the word press pages list. I have been trying to find documentation on this specific function for wordpress but it's a bit difficult to explain correctly in a google search.
You can "load the pages" via the pre_get_posts
action, like so:
add_action( 'pre_get_posts', 'my_admin_pre_get_posts' );
function my_admin_pre_get_posts( $q ) {
// Check whether the filter was clicked.
if ( isset( $_GET['post_parent'] ) ) {
$screen = is_admin() ? get_current_screen() : null;
// And that it's the edit pages page.
if ( $screen && 'edit-page' === $screen->id ) {
$post_parent = (int) $_GET['post_parent'];
$q->set( 'post_parent', $post_parent );
}
}
}