I hidden some pages using 'parse_query'
hook, but the count for ‘Published’ pages didn’t changed… Where I should hook to change it?
My code so far:
$query->query_vars['post__not_in'] = array(4);
I hidden some pages using 'parse_query'
hook, but the count for ‘Published’ pages didn’t changed… Where I should hook to change it?
My code so far:
$query->query_vars['post__not_in'] = array(4);
You must be logged in to post a comment.
Yes, the count for pages in various statuses that you see above the list table is obtained running
wp_count_posts
but the pages in the table are obtained running aWP_Query
and the 2 things are completely unrelated.If you want to also modify the count, you have to filter also the output of
wp_count_posts
using the'wp_count_posts'
filter hook.Also you should check the status of the page(s) you want to exclude from edit, because
wp_count_posts
count all the statuses separately.So we have 2 tasks:
I’ll write 2 functions, for the 2 tasks, and in both I need to check if we are in admin and if the current user has the needed capability and finally if the current screen is the right one. I’ll write an addtional function that does these checks, to avoid writing same code 2 times:
Now we can add the 2 hooks for out 2 tasks, I’ll add these 2 hooks inside a
'load-edit.php'
action:Now we can remove the pages from being queried:
and adjust the counts (see inline comments for explaination):
The post count uses the
wp_count_posts()
function, which ignores any query filters. You’ll need to tweak it manually with the use of thewp_count_posts
filter: