wp query - Exclude authors IDs from WP_Query

I am using this code, trying to exclude specific authors from WP_Query, however the author IDs in the array are not bein

I am using this code, trying to exclude specific authors from WP_Query, however the author IDs in the array are not being excluded. Any ideas please?

<?php
$args = array(
    'meta_query' => array(
        array('who' => 'authors')
    ),
    array( 'author__not_in' => array(10, 3, 4) )
);
$site_url = get_site_url();
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
?>

I am using this code, trying to exclude specific authors from WP_Query, however the author IDs in the array are not being excluded. Any ideas please?

<?php
$args = array(
    'meta_query' => array(
        array('who' => 'authors')
    ),
    array( 'author__not_in' => array(10, 3, 4) )
);
$site_url = get_site_url();
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
?>
Share Improve this question edited Jul 28, 2019 at 6:00 Sally CJ 40.3k2 gold badges29 silver badges50 bronze badges asked Jul 27, 2019 at 22:24 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

exclude specific authors from WP_Query

You can do it like so:

$args = array(
    'author__not_in' => array( 10, 3, 4 ),
);
$posts_query = new WP_Query( $args );

But if you meant "from WP_User_Query", then in WP_User_Query, you should use the exclude parameter, and that array('who' => 'authors') shouldn't be in meta_query:

$args = array(
    'exclude' => array( 10, 3, 4 ), // not author__not_in
    'who'     => 'authors',         // not in meta_query
);
$users_query = new WP_User_Query( $args );

For the full list of parameters, refer to WP_User_Query::prepare_query() for WP_User_Query, or WP_Query::parse_query for WP_Query.

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

相关推荐

  • wp query - Exclude authors IDs from WP_Query

    I am using this code, trying to exclude specific authors from WP_Query, however the author IDs in the array are not bein

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信