Skip to main content
29 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
21 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.7k
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,804
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
  • 762
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.7k
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
  • 477
6 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 ...
scott8035's user avatar
  • 220
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

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,754
5 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,279
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
5 votes
Accepted

Users table missing from Database

Oh, dear! Never mind! There really IS a wp_users table. I just realised that there is a second page to the list. My wp_users table was at the top of the second page of the navigation panel! I have ...
SunnyOz's user avatar
  • 175
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

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,369
4 votes
Accepted

WP User Query fails when searching meta queries and search columns

Combining a meta query with a search for a keyword will return posts which match both the search query and the result of the meta query (even if you're using relation => OR in the meta query). ...
Emil's user avatar
  • 470
4 votes
Accepted

ACF Upload Image in front-end with custom form

Ok, I got it to work with the 'media_handle_upload' (pointed out by @Piyush) and tweaking a little bit with my form code. So, here is what I did: First - Make sure your form has the attribute '...
Marcelo Henriques Cortez's user avatar
4 votes
Accepted

How to insert new element to existing array in usermeta?

Let's analyze your code and what it does. Assuming that the current fruits stored in the database are 'pineapple' and 'orange', get_user_meta(2, 'fruits', false) will return something like this: ...
swissspidy's user avatar
  • 3,844
4 votes
Accepted

How to position user meta data field

WordPress doesn't support such field placement in user profile. If you absolutely need to have your meta field after Nickname, you can use javascript to move form field from one place to another. Look ...
Vitauts Stočka's user avatar
4 votes
Accepted

is_author(get_current_user_id()) returns false when author id and user id match

Are you sure you're doing it within the loop? The is_author function checks if $wp_query is set. Another option would be to try this: $current_user = wp_get_current_user(); if (is_user_logged_in() &...
Nate Allen's user avatar
  • 2,086
4 votes
Accepted

'profile_update' hook alternative for WooCommerce user meta data

I got it working. The key was the woocommerce_update_customer action. In the end my function was triggered only by these two actions: add_action('user_register','get_all_user_data', 99); add_action('...
Kristián Filo's user avatar
4 votes
Accepted

meta_query for a string inside a meta field containing a comma-separated list

Is there a smart way to meta_query so it matches just "IS, but not "TS-IS"? The WordPress meta query class (WP_Meta_Query), which among others, is used with the posts (WP_Query) and ...
Sally CJ's user avatar
  • 39.3k
3 votes

Gather posts into a cart/lightbox and share with another user

Register a collection post type to represent a single collection. You'll get permalinks and rewrite rules to resolve the requests for free. Insert a new collection post for a user when they create a ...
Milo's user avatar
  • 78.5k
3 votes
Accepted

The Simple and Correct Way to Add User Meta

Trying to detect when a UI was triggered, is indeed the wrong general approach (unless you want to tie to the UI). A proper one will be to hook on the user_register action. add_action( 'user_register'...
Mark Kaplun's user avatar
  • 23.4k

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