Last active
April 19, 2019 11:47
-
-
Save dnshulga/78fb89b30a406a22e157b4fae1be2203 to your computer and use it in GitHub Desktop.
How to fix counters on Pages section after hiding of pages from dashboard Wordpress? Here we go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'pre_get_posts' ,'dnshulga_exclude_pages' ); | |
function dnshulga_exclude_pages( $query ) { | |
if( !is_admin() ) | |
return $query; | |
global $pagenow; | |
if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) ) | |
$query->set( 'post__not_in', array(213, 221) ); //ids of pages to hide | |
return $query; | |
} | |
add_filter('views_edit-page','dnshulga_correct_page_counters'); | |
function dnshulga_correct_page_counters( $views ){ | |
$html = explode('<span class="count">(',$views['all']); | |
$count = explode(')</span>',$html[1]); | |
$count[0] -= 2; //how much minus? length of array from previous function | |
$views['all'] = $html[0].'<span class="count">('.$count[0].')</span>'.$count[1]; | |
$html = explode('<span class="count">(',$views['publish']); | |
$count = explode(')</span>',$html[1]); | |
$count[0] -= 2; | |
$views['publish'] = $html[0].'<span class="count">('.$count[0].')</span>'.$count[1]; | |
return $views; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment