Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

Skip to main content

MB User Meta

MB User Meta helps you to add custom fields to user profile.

user meta

The extension works only on the back end. If you want to edit user profile on the front end, please see MB User Profile.

Adding fields to user profile

Registering custom fields for users is similar to posts. The only difference here is you need to specify a parameter 'type' => 'user':

add_action( 'rwmb_meta_boxes', function( $meta_boxes ) {
$meta_boxes[] = array(
'title' => 'Contact Info',
'type' => 'user', // THIS: Specifically for user

'fields' => array(
array(
'name' => 'Mobile phone',
'id' => 'mobile',
'type' => 'tel',
),
array(
'name' => 'Work phone',
'id' => 'work',
'type' => 'tel',
),
array(
'name' => 'Address',
'id' => 'address',
'type' => 'textarea',
),
array(
'name' => 'City',
'id' => 'city',
'type' => 'select_advanced',
'options' => array(
'hanoi' => 'Hanoi',
'hcm' => 'Ho Chi Minh City'
),
),
),
);
$meta_boxes[] = array(
'title' => 'Custom avatar',
'type' => 'user', // THIS: Specifically for user

'fields' => array(
array(
'name' => 'Upload avatar',
'id' => 'avatar',
'type' => 'image_advanced',
'max_file_uploads' => 1,
),
),
);

return $meta_boxes;
} );

Result:

User meta screenshot

Data

WordPress provides an identical way to store values in the meta tables for post / term / user. This extension utilizes that API and stores field value in the user meta exactly like post meta.

Getting field value

You're able to use helper function rwmb_meta() to get field value:

$value = rwmb_meta( $field_id, ['object_type' => 'user'], $user_id );
echo $value;

The code is very similar to getting post meta. The differences are:

  • In the 2nd parameter, you need to pass 'object_type' => 'user', and
  • In the last parameter, you need to pass the user ID

Other parameters are the same as for posts. Please see this documentation for details.

caution

It requires the extension version 1.1+ to use the helper function. If you're using an older version, please update now.