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 current user is blocked by checking current user meta 'blocking_users' to get the blocked users from it.

0

This a:1:{i:0;s:1:"3";} is the serialized version of an array in PHP. You can unserialize it by using the function unserialize like below-

$data = unserialize('a:1:{i:0;s:1:"3";}');

So after unserialize inside $data you'll get an array like below-

Array
(
    [0] => 3
)

This array will contain the user ID which is blocked by the user who is the owner of the user meta.

Now here you can run a foreach loop on $data and using get_user_by function you get all the users.

Hope that helps.

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.