In your original code, you’re not passing an operator to meta_compare
. Note that get_users()
does not define a default operator. Try using '='
:
$args = array(
'meta_key' => 'custom-usermeta',
'meta_value' => $cat_id,
'meta_compare' => '='
);
$users = get_users( $args );
As a diagnostic, you might make sure that the problem isn’t the saving/querying by your custom user metadata. Replace the meta_key and meta_value with one of the default WP user meta keys, just to see if anything is returned. (Easiest might be the user role?)
And this one is a long-shot, but: even though the get_users()
Codex documentation says otherwise, from what I can gather from source, the meta_query
for WP_user_query
should be the same as the meta_query
for WP_query
– in which case, have you tried putting your meta query in an array? e.g.:
$args = array(
array(
'meta_key' => 'custom-usermeta',
'meta_value' => $cat_id
)
);
$users = get_users( $args );