28 votes
Accepted

how to get list of all users and their metadata

I think you should use wp-api functions which will do everything for you. get_users() function will get all users data just define fields which u require. get_user_meta() function will get usermeta ...
Syed Fakhar Abbas's user avatar
20 votes
Accepted

Check if user is admin by user ID

You worded it as you want to check if user has administrator role. It is considered more proper to check for capability, relevant to specific action. In practice this is usually expressed as ...
Rarst's user avatar
  • 99.3k
15 votes
Accepted

How to filter users on admin users page by custom meta field?

UPDATE 2018-06-28 While the code below mostly works fine, here is a rewrite of the code for WP >=4.6.0 (using PHP 7): function add_course_section_filter( $which ) { // create sprintf templates ...
morphatic's user avatar
  • 391
14 votes

get_user_meta() doesn't include user email?

Just wanted to let you know you have get_user_meta and get_userdata. The email address can be found using the get_userdata function. For the current user this code can apply: <?php $user_id =...
Mark van den Ing's user avatar
11 votes
Accepted

How to echo billing phone number under My Account in Woocommerce?

You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure $customer_id is the ID of the user - you probably want ...
TheDeadMedic's user avatar
  • 36.3k
11 votes
Accepted

Difference between update_user_meta and update_user_option

In layman terms there is no major difference! update_user_option() uses update_user_meta() internally. The only difference is update_user_option() prefix the option name with database table prefix + ...
Sumit's user avatar
  • 4,764
9 votes

remove user_meta data from database for all users

This is a super old post, for all you future readers, you can use the delete_metadata() function to achieve this with a lot less DB overhead: delete_metadata( 'user', // the meta type ...
bartboy011's user avatar
9 votes

how to get specific fields from get_user_meta()

The function's arguments are as follows: user ID, custom field name (meta key), data return method (optional). So if you wanted to grab data in usermeta with the key of 'member_zip_code', you would ...
Edward's user avatar
  • 377
9 votes

Save custom user meta on registration

You have to trigger the following hooks: user_register personal_options_update edit_user_profile_update add_action('user_register', 'addMyCustomMeta'); add_action('personal_options_update', '...
Aishan's user avatar
  • 752
8 votes
Accepted

Create custom user role (client) that can create another custom user role (employee) of that client

Clients get added by admins, clients have a parent child relationship with employees which makes filtering easy. So all we need to do is remove anything that doesn't have to do with employees and ...
Howdy_McGee's user avatar
  • 20.5k
7 votes
Accepted

Update user meta using with ajax

Alright, there's a few things that isn't standardized WordPress so I've put together a minimal script which I'll explain piece by piece. Hopefully clear things up for you by the time you get to the ...
Howdy_McGee's user avatar
  • 20.5k
7 votes

Difference between update_user_meta and update_user_option

Both write their data in the “usermeta” table. User options stored in the usermeta table retain the wordpress table prefix e.g. wp_ whereas the user meta also stored in the usermeta table doesn't. ...
Jarod Thornton's user avatar
7 votes

How to use the WP REST API for new user registration (sign up form)?

hopefully you've found the answer already. Here's our solution, for your reference. :D The following code should add User Registration via REST API to your WordPress Website. It supports Registration ...
Jack Song's user avatar
  • 391
7 votes
Accepted

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 ...
Jacob Peattie's user avatar
6 votes

Query users by custom taxonomy and user role

Apparently there is no core implementation of 'tax_query' in WP_User_Query yet. Check the ticket here for more info --> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an ...
RafaSashi's user avatar
  • 447
6 votes
Accepted

What is rich_editing?

The rich_editing user option stores this check box value: wether or not do enable the visual editor for that particular user. If it's disabled then the content editor will look like this:
birgire's user avatar
  • 66.7k
6 votes
Accepted

Grouping users under parent user

Roles First of all you need to register the 2 roles, look at add_role. When you register the role, you are free to assign any capability you want. Only be careful to add the roles when your theme / ...
gmazzap's user avatar
  • 45.9k
6 votes

How to make a custom column on the Users admin screen sortable?

This is my code which adds a sortable custom column (called Vendor ID) to the users table: function fc_new_modify_user_table( $column ) { $column['vendor_id'] = 'Vendor ID'; return $column; } ...
ban-geoengineering's user avatar
5 votes
Accepted

How can I sort get_users() by any value (last_name, user defined fields and more)

get_users() does not allow you to directly sort by whatever you like, but there are ways around it. The Codex for get_users() says: orderby - Sort by 'ID', 'login', 'nicename', 'email', 'url', '...
flomei's user avatar
  • 1,054
5 votes

user_login vs. user_nicename

I wrote a blog post about WordPress names to document this. Here's the scoop: Username: column "user_login" from wp_users, this is what would typically be called a "user ID" in plain English. ...
scott8035's user avatar
  • 210
5 votes
Accepted

How to get last login Access Date and time

Finally I found answer by myself. Let's explore it with two user meta's current_login, last_login.Lets see the code. //function for setting the last login function set_last_login($login) { $...
Kvvaradha's user avatar
  • 926
5 votes

Hide a user from WordPress

You're wanting to hide a user from WordPress in three places: The user list in the admin The count above that user list The user's author archive on the front-end As you mentioned, you've already ...
Tim Malone's user avatar
  • 4,684
5 votes

get posts based on meta value of the author

Get for all users / authors with user meta field. meta1 = true $args = array( 'meta_key' => 'meta1', 'meta_value' => 'true', 'meta_compare' => '=', 'fields' => ...
Anwer AR's user avatar
  • 1,007
5 votes
Accepted

\WP_User Object | What's the Difference Between {caps} and {allcaps}?

Examining the comments for the properties in the WP_User class reveals that allcaps is: All capabilities the user has, including individual and role based. And caps is: The individual ...
Jacob Peattie's user avatar
5 votes
Accepted

How to get user metadata for social media url?

Use get_user_meta( $user->ID, 'facebook' , true ); But let me clarify you, none of the social media fields are WP core fields. You are using Yoast SEO, and these fields are Yoast SEO features. FYI: ...
Bikram's user avatar
  • 338
4 votes

Adding fields to the "Add New User" screen in the dashboard

You need to do 2 things. Register fields Save fields Note: Below example works only for administrator user role. 1. Register fields For Add New User use action user_new_form For User Profile use ...
maheshwaghmare's user avatar
4 votes

How to filter users on admin users page by custom meta field?

I tested your code in both Wordpress 4.4 and in Wordpress 4.3.1. With version 4.4, I encounter exactly the same issue as you. However, your code works correctly in version 4.3.1! I think this is ...
Linnea Huxford's user avatar
4 votes

How to filter users on admin users page by custom meta field?

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches for a similar naming convention, namely course_section1 (...
birgire's user avatar
  • 66.7k
4 votes

Check if user is admin by user ID

You can use get_userdata() or get_user_by() by passing user id yo can get user object. From which you get role. $user = get_userdata( $user_id ); if(!empty( $user ) && $user){ $user->...
bravokeyl's user avatar
  • 3,339
4 votes

Check if user is admin by user ID

I'm just adding to @Rarst answer. Technically you can supply the role name to those functions, so current_user_can( 'administrator' ) or user_can( $user_id, 'administrator' ) would also work but it is ...
bynicolas's user avatar
  • 2,259

Only top scored, non community-wiki answers of a minimum length are eligible