SO网友:Ignat B.
要从帖子编辑器页面中删除特定的All()和published()帖子计数,您可以:
// Create a specific hook
add_filter("views_edit-post", \'custom_editor_counts\', 10, 1);
function custom_editor_counts($views) {
// var_dump($views) to check other array elements that you can hide.
unset($views[\'all\']);
unset($views[\'publish\']);
return $views;
}
让我们更高级地从Posts editor管理表中删除All(),从Pages editor管理表中删除Published()。
// Create a hook per specific Admin Editor Table-view inside loop
foreach( array( \'edit-post\', \'edit-page\') as $hook )
add_filter( "views_$hook" , \'custom_editor_counts\', 10, 1);
function custom_editor_counts($views) {
// Get current admin page view from global variable
global $current_screen;
// Remove count-tab per specific screen viewed.
switch ($current_screen->id) {
case \'edit-post\':
unset($views[\'all\']);
break;
case \'edit-page\':
unset($views[\'publish\']);
break;
}
return $views;
}
参考文献:
[Hide the post count behind Post Views (Remove All, Published and Trashed) in Custom Post Type]UPDATE
用代码更新了答案如何更新特定用户的帖子数量,不包括“所有”和“发布”视图。最近在WP 4.3二一五上测试。
add_filter("views_edit-post", \'custom_editor_counts\', 10, 1);
function custom_editor_counts($views) {
$iCurrentUserID = get_current_user_id();
if ($iCurrentUserID !== 0) {
global $wpdb;
foreach ($views as $index => $view) {
if (in_array($index, array(\'all\', \'publish\')))
continue;
$viewValue = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type=\'post\' AND post_author=$iCurrentUserID AND post_status=\'$index\'");
$views[$index] = preg_replace(\'/\\(.+\\)/U\', \'(\' . $viewValue . \')\', $views[$index]);
}
unset($views[\'all\']);
unset($views[\'publish\']);
}
return $views;
}