admin管理员组文章数量:1287919
Ok, so right now I can easily echo the number of posts that has a specific meta_key
and meta_value
:
$query = new WP_Query(
array(
'meta_key' => 'usp-custom-1',
'meta_value' => get_permalink()
)
);
echo $query->found_posts;
I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.
I'm trying this:
$query = new WP_User_Query(
array(
'meta_key' => 'cash_out_status',
'meta_value' => 'pending'
)
);
echo $query->found_users;
But the above doesn't display anything.
I guess I'm making a mistake somewhere in the code.
Any help would be greatly appreciated.
Thanks.
Ok, so right now I can easily echo the number of posts that has a specific meta_key
and meta_value
:
$query = new WP_Query(
array(
'meta_key' => 'usp-custom-1',
'meta_value' => get_permalink()
)
);
echo $query->found_posts;
I'm trying to do something similar except for echoing the number of users that has a specific user_meta data.
I'm trying this:
$query = new WP_User_Query(
array(
'meta_key' => 'cash_out_status',
'meta_value' => 'pending'
)
);
echo $query->found_users;
But the above doesn't display anything.
I guess I'm making a mistake somewhere in the code.
Any help would be greatly appreciated.
Thanks.
Share Improve this question edited Sep 8, 2021 at 17:39 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Sep 8, 2021 at 16:43 robert0robert0 2032 silver badges11 bronze badges 1 |1 Answer
Reset to default 1We have the public properties:
WP_Query->found_posts
WP_Comment_Query->found_comments
WP_Network_Query->found_networks
WP_Site_Query->found_sites
but then comes this private property (that's also made public via magic getter):
WP_User_Query::$total_users
but not found_users
as expected, so the confusion is natural :-)
Look into the public get_total()
method and the count_total
bool attribute (true by default) in the docs.
本文标签: Echo the number of users using WPUserQuery
版权声明:本文标题:Echo the number of users using WP_User_Query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741332298a2372836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
'meta_compare' => '=',
to your array? – rudtek Commented Sep 8, 2021 at 18:01