How to get users by a custom field / by user meta data?

What is the exact meta_key and meta_value for the field I created
using the function custom_user_profile_fields ?

created_by and some user ID, for example:

$args = array(  
        'meta_key'     => 'created_by',
        'meta_value'   => 123,
)

You could use a meta_query for more complex searches.

$args = array( 
  'meta_query' => array(
    array(
        'key' => 'created_by',
        'compare' => 'EXISTS',
    ),
  ) 
);
var_dump(get_users($args));

Essentially, though, what you are doing is correct.

Leave a Comment