Getting a user by custom field

Bryan Adams Posted in Technical Support 4 years ago

Do we have example on how to get a user by a custom field?

In the docs, we can get a user by ossn_user_by_email or ossn_user_by_guid but how about custom fields?

Let's say I have a random_field field in the users table. And do something like below.

$user = input('random_field');
$user = ossn_user_by_random_field($user); // or whatever

$user->data->another_field = true;
if($user->save()){}

Any help would be much appreciated.

Replies
ph Bryan Adams Replied 4 years ago

Thanks Arsalan!

Indonesian Arsalan Shah Replied 4 years ago

Here if you wanted to list all users with that field

$users = new OssnUser;
$list  = $users->searchUsers(array(
        'entities_pairs' => array(
                array(
                    'name' => 'another_field',
                    'value' => true,
                ),
        )                                  
));
echo ossn_dump($list);

..