Each of the 7,000+ users on my site has around 25 keys in the usermeta table. I won't list them all, but two of the keys are "access_code" and "association".
There are several dozen unique access codes for my site and each user is assigned only one access code.
Here's what I'm trying to do: I want to find all the users with the access_code key with value "abc" and for each of those users where that value is true, their association key would change to "XYZ Corporation".
Any thoughts?
Each of the 7,000+ users on my site has around 25 keys in the usermeta table. I won't list them all, but two of the keys are "access_code" and "association".
There are several dozen unique access codes for my site and each user is assigned only one access code.
Here's what I'm trying to do: I want to find all the users with the access_code key with value "abc" and for each of those users where that value is true, their association key would change to "XYZ Corporation".
Any thoughts?
Share Improve this question asked Oct 22, 2018 at 21:14 Eric StevensonEric Stevenson 31 bronze badge1 Answer
Reset to default 0You would need to use a meta query for this.
$meta_query_args = array(
array(
'key' => 'access_code',
'value' => 'abc',
'compare' => '='
)
);
$args = array(
'meta_query' => $meta_query_args
);
$users = get_users( $args );
// User Loop
foreach ( $users as $user ) {
update_user_meta( $user->ID, 'association', 'XYZ Corporation');
}