admin管理员组文章数量:1122846
i have created user vote that can vote users or author of posts. so for example have 4 users which looks:
user --- ID=1 --- META KEY='_thumbs_rating_up' --- META VALUE='13'
user --- ID=2 --- META KEY='_thumbs_rating_up' --- META VALUE='17'
user --- ID=3 --- META KEY='_thumbs_rating_up' --- META VALUE='8'
user --- ID=4 --- META KEY='_thumbs_rating_up' --- META VALUE='241'
So i must order these users by user meta key and meta value from heighest to lowwer. So i have these code now but order is not correct:
<?php
$args = array(
'role' => 'Seller',
'meta_key' => '_thumbs_rating_up',
'orderby' => 'meta_value_num'
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<p>' . get_avatar( $user->ID, 32 ) . '</p>';
echo '<p>' . get_user_meta($user->ID, '_thumbs_rating_up', true). '</p>';
echo '<p>' . $user->display_name . '</p>';
}
} else {
echo 'No users found.';
}
?>
what i do wrong or simply can not order my custom meta key??????
- i find the post here which is similar but i dont know how can i help with these answers: Sort users by meta_value_num
i have created user vote that can vote users or author of posts. so for example have 4 users which looks:
user --- ID=1 --- META KEY='_thumbs_rating_up' --- META VALUE='13'
user --- ID=2 --- META KEY='_thumbs_rating_up' --- META VALUE='17'
user --- ID=3 --- META KEY='_thumbs_rating_up' --- META VALUE='8'
user --- ID=4 --- META KEY='_thumbs_rating_up' --- META VALUE='241'
So i must order these users by user meta key and meta value from heighest to lowwer. So i have these code now but order is not correct:
<?php
$args = array(
'role' => 'Seller',
'meta_key' => '_thumbs_rating_up',
'orderby' => 'meta_value_num'
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<p>' . get_avatar( $user->ID, 32 ) . '</p>';
echo '<p>' . get_user_meta($user->ID, '_thumbs_rating_up', true). '</p>';
echo '<p>' . $user->display_name . '</p>';
}
} else {
echo 'No users found.';
}
?>
what i do wrong or simply can not order my custom meta key??????
- i find the post here which is similar but i dont know how can i help with these answers: Sort users by meta_value_num
2 Answers
Reset to default 0The QA that you have linked to is related but not needed here.
meta_value_num
is still not part of the user_query core and so, your meta_value_num parameter has no effect on the query.
Just use meta_value
as described on codex and you'll get what you want.
you can missing the ORDER = DESC. Try this
<?php
$args = array(
'role' => 'Seller',
'meta_key' => '_thumbs_rating_up',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
本文标签: User list order by user meta
版权声明:本文标题:User list order by user meta 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289417a1928300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论