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 ...
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 ...
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 ...
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 =...
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 ...
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 + ...
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
...
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 ...
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', '...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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:
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 / ...
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;
}
...
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', '...
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.
...
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) {
$...
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 ...
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' => ...
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 ...
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: ...
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 ...
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 ...
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 (...
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->...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
user-meta × 883users × 252
php × 76
custom-field × 72
user-roles × 56
functions × 55
user-registration × 54
profiles × 54
database × 47
meta-query × 41
wp-user-query × 40
plugin-development × 37
post-meta × 33
mysql × 32
plugins × 31
array × 30
custom-post-types × 29
author × 28
wp-query × 27
customization × 22
query × 22
wpdb × 22
advanced-custom-fields × 20
meta-value × 19
wp-admin × 18