$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to set a user meta key value based on another user meta key value|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to set a user meta key value based on another user meta key value

matteradmin8PV0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

You 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');
}
Post a comment

comment list (0)

  1. No comments so far