Custom Fields
Re-Envisioned
Support MB User Profile Updating usermeta for a custom meta_key

This topic contains 4 replies, has 2 voices, and was last updated by  Matt 1 month, 3 weeks ago.

  • Creator
    Topic
  • #15732
    Resolved
    Matt
    Participant

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #15735

    Anh Tran
    Keymaster

    Hi,

    Did you create a meta box with premium_categories field for the users?

    #15736

    Matt
    Participant

    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;
    }
    #15737

    Anh Tran
    Keymaster

    Hi, can you try the taxonomy_advanced field? The taxonomy field will set post terms, which doesn’t work for users.

    #15738

    Matt
    Participant

    That worked. Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.