내 wordpress mockup에서 ref_credit라고하는 사용자에 대해 meta_value를 사용하고 있습니다. 산드로에 대한이 메타 값은 다음과 같습니다은 mysql 행 (php wordpress)의 항목 수를 비교합니다.
174 1 ref_credit a:2:{i:0;s:1:"9";i:1;s:2:"10";}
그가 ID로 사용자를 언급의 의미 = 9, 10
다른 사용자 meta_value는 다음과 같습니다
209 9 ref_credit a:1:{i:0;s:2:"11";}
그는 단 한 사용자 ID를 언급 = 11.
이제 간단한 리더 보드를 만들고 싶습니다. 로직을 완전히 잘못 생각했습니다. 내 코드가이 값과 주문을 비교한다는 것을 이해합니다. 추천 된 사용자 수에 따라 주문하고 싶습니다.
아이디어가 있으십니까?
완성 기능이 있습니다 :
//get_users calls WP_User_Query and returns an array of matching users
$users = get_users(
array( 'fields' => 'all_with_meta',
'meta_query' => array(array('key' => 'ref_credit', // the meta field (or key) we want to target
'compare' => '>=' // comparison method (optional: =, >, <, etc)
)))
);
//custom function for comparing the data we want to sort by
function cmp($a, $b){
if ($a->points == $b->points) {
return 0;
}
return ($a->points > $b->points) ? -1 : 1;
}
//usort sorts our $users array with our function cmp()
usort($users, 'cmp');
//leaving an array of $users sorted by the value of meta 'points'
echo '<ol>';
foreach ($users as $user) {
echo '<li>' . $user->display_name . '</li>';
}
echo '</ol>';