corcel / corcel

Use WordPress backend with Laravel or any PHP application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can to select all user by a specific role in corcel using usermeta

Unstinted opened this issue · comments

  • Corcel Version: #.#.#
  • Framework Name & Version:
  • PHP Version:
  • Database Driver & Version:

Description:

Please I have an app that populate user to a select box, but I donr want all the users to be populated.

Please can some help out.

Steps To Reproduce:

@Unstinted feel free to show us the code you are working with.

This should give you a good start:

use Corcel\Model\Meta\UserMeta as UserMeta;

...

$users = UserMeta::where('meta_key', 'wp_capabilities')->where('meta_value', 'like', '%administrator%')->get();

Iterating over $users will give you $user->user_id

There may be a better way, but at the moment, I'm not seeing it.

If you're in the market to find the role for a given user, you can do this:

$user = User::find(1);
$meta = unserialize($user->meta->wp_capabilities);

...which if that user is an administrator, would return an array:

[
    "administrator" => true
]

HTH