Get user_meta values for a user for an array of meta_keys?

get_user_meta() with omitted key argument will return all data for the object. Trying to retrieve metadata selectively is usually pointless optimization from performance point of view, since everything built on Metadata API tends to just query all data anyway and cache it (which in turn object cache plugin makes persistent and snappy).

Randomize Users

I don’t see an “orderby Rand()” parameter for either get_users or WP_User_Query. There is a filter called pre_user_query that could be used but I am not sure I see the benefit of that when shuffle will randomize the array you already have. $args = array( ‘fields’ => ‘all_with_meta’, ‘exclude’ => array(1), ); $users = get_users( … Read more

How do I add a dropdown list of numbers 1 – 1000 as an extra profile field?

you can save the 1000 conditional checks by using str_replace and your code would be much more efficient, something like this: //create the select options $options=””; for($i=1;$i<=1000;$i++) { $options.= ‘<option value=”‘.$i.'”>’.$i.'</option>’; } //get the saved data $saved = get_the_author_meta( ‘number_pick’, $user->ID ); $saved = (!empty($saved))? $saved: false; if ($saved) //if there is a saved data … Read more

WordPress REST API and User meta data

There’s a lot of stuff saved as user meta that has no business being sent over the REST API, therefore the default endpoints do not include every piece of arbitrary meta automatically. If you want a piece of meta to appear in the REST API responses you need to register it with register_meta(), with show_in_rest … Read more

Multiple Email Addresses, One User

You can use update_user_meta() and add_user_meta(), just store all the email addresses in an array in a new field. If you have a requirement, such as preventing duplicates, run a validation function that checks for that before updating the database.

When is a user’s meta data table loaded?

This page gives you a typical wordpress load http://codex.wordpress.org/Plugin_API/Action_Reference You can see, the current user is available after the theme is setup but before init. If you are calling these functions within the theme then you will be fine. Otherwise make sure any functions that reference the current user are called using hooks that run … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)