Support Forum
Support › MB User Profile › Updating usermeta for a custom meta_keyResolved
I am using MB User Profile to have users submit their forms on the front end. This works with updating the default fields like first_name and description. However, it does not update metadata for custom fields. I want users to be able to select from a list of categories so I can show them custom content based on their interests.
If I add this, it will create/update usermeta for premium_categories when I save a profile in the admin area.
add_action( 'personal_options_update', 'save_premium_categories' );
add_action( 'edit_user_profile_update', 'save_premium_categories' );
function save_premium_categories( $user_id ){
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'premium_categories', $_POST['premium_categories'] );
}
However, it still does not update when I save on the front end. Any ideas how I can make this work?
Hi,
Did you create a meta box with premium_categories
field for the users?
Yes, I used the Builder add-on, and this is the code it gave me.
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array (
'title' => 'Premium Categories',
'id' => 'premium_categories',
'autosave' => true,
'fields' => array(
array (
'id' => 'premium_categories',
'type' => 'taxonomy',
'name' => 'Sections',
'desc' => 'Choose which types of articles you want to appear in your custom feed.',
'taxonomy' => 'category',
'field_type' => 'select_advanced',
'multiple' => true,
'select_all_none' => true,
),
),
'type' => 'user',
);
return $meta_boxes;
}
Hi, can you try the taxonomy_advanced
field? The taxonomy
field will set post terms, which doesn't work for users.
That worked. Thank you!