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?

0

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);
  • how can print it? and how can choose to get blocking_users for the current user only – Yogu Jun 3 '17 at 16:14
  • @Yogu I have added code in the above answer to achieve this. – Vinod Dalvi Jun 5 '17 at 15:27
  • I already try this but it gives me: The blocking_users value for user id 1 is: Array. – Yogu Jun 5 '17 at 17:19
  • I have modified code so please try again. – Vinod Dalvi Jun 6 '17 at 7:13
  • Really thank you for your help, it's now give me: Array ( [0] => Array ( ) ) not the users name that in blocking_users meta. can this code help: mattvarone.com/wordpress/list-users-with-wp_user_query – Yogu Jun 6 '17 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.