0

what is the correct filter hook to manage post list view. I want to show only posts by user roles.

I will show you what I mean. I want to filter what posts will be listed not change or edit columns.

enter image description here

1

The same way you would do it on the frontend, with pre_get_posts. Combine it with get_current_screen() so you can tell which area of the admin you're in, and hook the filter on admin_init so it doesn't impact the frontend.

There's also the restrict_manage_posts which will let you add inputs to the filter column:

https://developer.wordpress.org/reference/hooks/restrict_manage_posts/

Just note, that WP_Query can query for posts, and it can restrict by users, but not by role. You will need to fetch an array of the IDs of all the users in that role, then pass it to the query object via pre_get_posts to specify you only want posts that have those authors in that array of user IDs

  • Thanks. But not safe my problem. Because They should see their posts (inside their role) and see published post and a posts with a special post status. I think. I've to manipulate it with javascript. – yfain Sep 12 '19 at 11:19
  • @yfain can you re-word your comment? I don't understand what you wrote. Note that if it's a block of code you can copy paste that you're looking for, you won't find it. Any answer you get will explain how to do it, but we aren't here to do free dev work for you – Tom J Nowell Sep 13 '19 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.