admin管理员组文章数量:1418686
We are using this code to get a list of all contributors but we would like to exclude the admin from this list. Currently the admin and any role above the contributor role is being shown with this code.
$args = array('exclude' => array( 10, 18, 4, 15, 9 ), 'who' => 'contributors' );$wp_user_query = new WP_User_Query($args);
We are using this code to get a list of all contributors but we would like to exclude the admin from this list. Currently the admin and any role above the contributor role is being shown with this code.
$args = array('exclude' => array( 10, 18, 4, 15, 9 ), 'who' => 'contributors' );$wp_user_query = new WP_User_Query($args);
Share
Improve this question
asked Jul 29, 2019 at 14:15
JoaMikaJoaMika
6986 gold badges27 silver badges58 bronze badges
1
- We are just looking to get all contributors ONLY and exclude certain contributors from this list. I have tried to follow the documentation but couldn't figure this out. Also there doesn't seem to be a specific answer anywhere for this type of example. – JoaMika Commented Jul 29, 2019 at 14:29
1 Answer
Reset to default 2I realize now that you're not talking about WP_Query but WP_User_Query. Looking at the documentation for WP_User_Query it says this about the who
parameter:
- who (string) - Which users to query. Currently only 'authors' is supported. Default is all users.
Instead you can use the role parameter and exclude certain users by ID like so:
// Grab all contributors
$contributor_ids = new WP_User_Query( array(
'role' => 'contributor',
'exclude' => array( 10, 18, 4, 15, 9 )
) );
You can also pass multiple roles to the above. For more info check out the section on roles.
本文标签: wp queryExclude admin from WPQuery Contributors
版权声明:本文标题:wp query - Exclude admin from WP_Query Contributors 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287649a2651596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论