admin管理员组文章数量:1414642
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 badges1 Answer
Reset to default 1The 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
本文标签: plugin developmentFilter Hook for post table (not columns)
版权声明:本文标题:plugin development - Filter Hook for post table (not columns) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745170881a2645964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论