Multiple meta values for one meta key

If multiple entries are stored in a single meta key, then get_post_meta() will return an array of those values. get_post_meta( $post_id, ‘game’ ); // returns [‘game 1’, ‘game 2′] If you want to iterate through the collection, then you’ll just use a for-loop in PHP: $games = get_post_meta( $post_id, ‘game’ ); foreach( $games as $game … Read more

List users by meta_key and meta_value

What about putting the city/regions/whatever into an array you can loop through? Something like this: $cities = array( ‘Richmond’, ‘Chicago’, ‘New York’ ); foreach ( $cities as $city ) { ?> <h2><?php echo $city; ?></h2> <ul><?php foreach ( get_users_by_meta_data( ‘school_division’, $city ) as $user ) { ?> <li><?php echo $user->first_name; ?> <?php echo $user->last_name; ?></li> … Read more

get_user_meta returning empty when it’s NOT empty

I can confidently say that it is empty at the point at which your code checks the variable. The three possibilities are: $user_id is not set or is set to an incorrect value. As you don’t show the code that sets this value, I can’t tell. You are using the wrong key. Something is hooked … Read more

How to change user role using hook

Please edit your function and add code used below for adding user role in functions.php This is basic idea how roles can be added and removed and how you can check your filed values. Please use according to your requirements. add_action( ‘profile_update’, ‘my_profile_update’, 10, 2 ); function my_profile_update( $user_id, $old_user_data ) { // here you … Read more