最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How can get all users by current user meta?

programmeradmin4浏览0评论

I have a block system to make users block each other, My question is how to get all users by current user meta by the array?

When current user is blocked anther user it's saved as meta like this: a:1:{i:0;s:1:"3";} so user ID 1 block user ID 3.

So I need to make a specific page to get all users that the current user is blocked by checking current user meta blocking_users' to get the blocked users from it.

Any idea example how can make it?

I have a block system to make users block each other, My question is how to get all users by current user meta by the array?

When current user is blocked anther user it's saved as meta like this: a:1:{i:0;s:1:"3";} so user ID 1 block user ID 3.

So I need to make a specific page to get all users that the current user is blocked by checking current user meta blocking_users' to get the blocked users from it.

Any idea example how can make it?

Share Improve this question edited Aug 15, 2018 at 5:31 Castiblanco 2,1947 gold badges20 silver badges26 bronze badges asked Jun 3, 2017 at 7:33 YoguYogu 855 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can achieve this using get_users function and its meta_key argument as displayed below.

$users = get_users(array(
    'meta_key'     => 'blocking_users',
));

var_dump( $users );

To retrieve it for current user and print it, please use below code.

$user_id = get_current_user_id();
$key = 'blocking_users';
$single = false;
$blocking_users = get_user_meta( $user_id, $key, $single ); 
echo '<p>The '. $key . ' value for user id ' . $user_id . ' is: </p>'; 
print_r($blocking_users);
发布评论

评论列表(0)

  1. 暂无评论