admin管理员组文章数量:1130349
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');
}
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');
}
本文标签: How to set a user meta key value based on another user meta key value
版权声明:本文标题:How to set a user meta key value based on another user meta key value 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749240744a2338044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论