admin管理员组文章数量:1130349
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.
Share Improve this question asked Oct 31, 2018 at 17:30 peter kpeter k 54 bronze badges1 Answer
Reset to default 0You 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 );
}
}
}
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.
Share Improve this question asked Oct 31, 2018 at 17:30 peter kpeter k 54 bronze badges1 Answer
Reset to default 0You 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 );
}
}
}
本文标签: Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
版权声明:本文标题:Add view to admin menu to filter for specific criteria ( If post is child of specific Parent ) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749212804a2333656.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论