plugin development - Filter Hook for post table (not columns)

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

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.

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.

Share Improve this question asked Sep 10, 2019 at 11:06 yfainyfain 635 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745170881a4614915.html

相关推荐

  • plugin development - Filter Hook for post table (not columns)

    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

    6小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信