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 badges1 Answer
Reset to default 1You 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);