admin管理员组文章数量:1130349
I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.
is there a way to this? thank you so much!
I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.
is there a way to this? thank you so much!
Share Improve this question edited Mar 18, 2015 at 10:02 Daniele Chianucci asked Mar 17, 2015 at 17:08 Daniele ChianucciDaniele Chianucci 92 silver badges6 bronze badges1 Answer
Reset to default 2It's not clear what you're looking for here, but you could try to use the posts_where filter:
/**
* Remove posts, with a given status, on the edit.php (post) screen,
* when there's no post status filter selected.
*/
add_action( 'posts_where', function( $where, $q )
{
if( is_admin()
&& $q->is_main_query()
&& ! filter_input( INPUT_GET, 'post_status' )
&& ( $screen = get_current_screen() ) instanceof \WP_Screen
&& 'edit-post' === $screen->id
)
{
global $wpdb;
$status_to_exclude = 'project_close'; // Modify this to your needs!
$where .= sprintf(
" AND {$wpdb->posts}.post_status NOT IN ( '%s' ) ",
$status_to_exclude
);
}
return $where;
}, 10, 2 );
where you have to modify the $status_to_exclude status. Here we target the edit.php screen for the post post type. We make sure the post_status GET filter is not set.
So when you click on the All Posts admin menu link in the backend, this filtering is activated.
Hopefully you can adjust this further to your needs.
I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.
is there a way to this? thank you so much!
I created various custom post status options (like default ones: "published", "draft" and so on) and one of them is "project closed". I need to hide/exclude by default from post list in the backend the posts set under "project closed" post status.
is there a way to this? thank you so much!
Share Improve this question edited Mar 18, 2015 at 10:02 Daniele Chianucci asked Mar 17, 2015 at 17:08 Daniele ChianucciDaniele Chianucci 92 silver badges6 bronze badges1 Answer
Reset to default 2It's not clear what you're looking for here, but you could try to use the posts_where filter:
/**
* Remove posts, with a given status, on the edit.php (post) screen,
* when there's no post status filter selected.
*/
add_action( 'posts_where', function( $where, $q )
{
if( is_admin()
&& $q->is_main_query()
&& ! filter_input( INPUT_GET, 'post_status' )
&& ( $screen = get_current_screen() ) instanceof \WP_Screen
&& 'edit-post' === $screen->id
)
{
global $wpdb;
$status_to_exclude = 'project_close'; // Modify this to your needs!
$where .= sprintf(
" AND {$wpdb->posts}.post_status NOT IN ( '%s' ) ",
$status_to_exclude
);
}
return $where;
}, 10, 2 );
where you have to modify the $status_to_exclude status. Here we target the edit.php screen for the post post type. We make sure the post_status GET filter is not set.
So when you click on the All Posts admin menu link in the backend, this filtering is activated.
Hopefully you can adjust this further to your needs.
本文标签: adminHiding by default specific post status on backend list
版权声明:本文标题:admin - Hiding by default specific post status on backend list? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749022587a2304607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论