How to display custom user meta field on website?

Support MB User Meta How to display custom user meta field on website?Resolved

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #28849
    DannyDanny
    Participant

    I'm new to MB and got stuck with this.

    I've created a Select field (called Status) and added this to the Users using MB Builder.

    Then tried adding the shortcode [rwmb_meta id="status"] to a page.

    Nothing displayed. And I couldn't find any other topic mentioning how to do this, nor in the FB group.

    I apologize in advance if this wasn't the right forum to post this in.

    #28851
    Long NguyenLong Nguyen
    Moderator

    Hi Danny,

    You need to pass two attributes object_type and object_id (user ID) to the shortcode.

    [rwmb_meta id="color" object_id="1" object_type="user"]
    

    Get more details here https://docs.metabox.io/shortcode/#examples

    #28861
    DannyDanny
    Participant

    Hey Long, thank you for responding.

    Hmm.. if object_id is meant to retrieve the user ID, then this shortcode may not be usable. Because each user profile will have its own status reflected.

    Secondly, I tried using this
    [rwmb_meta id="status" object_id="2" object_type="user"]

    But the status value did not output when user_id=2 viewed the page with the shortcode.

    #28871
    Long NguyenLong Nguyen
    Moderator

    Hi Danny,

    If you want to get the user ID dynamically for each logged in user, you can use the WordPress function get_current_user_id() and follow the documentation to get the user meta https://docs.metabox.io/extensions/mb-user-meta/#getting-field-value

    #28872
    DannyDanny
    Participant

    Hmm.. seems like Metabox isn't as simple as I would've thought it to be for a non-programmer. (-_-||) And most of the documentation is very code driven.

    Guess I'd either shelf this, or take a much longer time wrapping my head around it.

    #28882
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Meta Box is a developer tool so you need to have basic coding knowledge to do more advanced cases with Meta Box.

    #28890
    DannyDanny
    Participant

    I see.

    Well, I've got Elementor Pro and I've installed the MB integrator plugin.

    Now I'm trying to get the status by using User Info (User Meta).

    For the meta key, I've tried using both Field ID and Field Group ID, but I still can't pull the data in Elementor.

    Is the meta key something else?

    #28894
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please refer to this topic to get the author (user) meta for a post
    https://support.metabox.io/topic/user-custom-fields-and-elementor-dynamic-content-for-author/

    #28898
    DannyDanny
    Participant

    Unfortunately, linked post wasn't helpful. I'm familiar with retrieving the common User Info via Elementor Pro. And when I tried to view your screen recording in the quoted post, it tells me; This item has exceeded its view limit!

    Anyway.. here's a screenshot of the meta key I'm asking about; https://imgur.com/a/OhBNkEr

    I've tried entering my field ID as you mentioned in another thread (https://support.metabox.io/topic/meta-field-key-without-shortcode/#post-24727). But it's still not retrieving the Select field's value or label.

    If this helps, here's the generated code from my field group via MB builder:

    <?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'  => __( 'Applicant status', 'your-text-domain' ),
            'id'     => 'applicant-status-mb',
            'type'   => 'user',
            'fields' => [
                [
                    'name'    => __( 'Status', 'your-text-domain' ),
                    'id'      => $prefix . 'applicant_status_mb',
                    'type'    => 'select',
                    'options' => [
                        'pending'    => __( 'Pending documents', 'your-text-domain' ),
                        'review'     => __( 'In review', 'your-text-domain' ),
                        'processing' => __( 'Processing', 'your-text-domain' ),
                        'improve'    => __( 'To improve', 'your-text-domain' ),
                        'complete'   => __( 'Completed', 'your-text-domain' ),
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    #28902
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I see the dynamic tag User Info shows the user meta as well, screen record https://share.getcloudapp.com/4gunJRvB

    And please notice that this tag helps you to show the status of the logged-in user.

    #28905
    DannyDanny
    Participant

    Hey Long, I managed to retrieve the value after resetting my WordPress. Not sure what happened there.

    I've got 1 last question..

    I read here (https://docs.metabox.io/fields/select/) that Select will return the Value of the field. Is there a way to display the Label in Elementor?

    #28916
    Long NguyenLong Nguyen
    Moderator

    Hi,

    It's not possible, Elementor only supports showing the value of the option. You can try to create a shortcode by coding to show the value.

    #40905
    leennleenn
    Participant

    Hi Long,

    I tried to display user's custom field by adding this code
    `<?php
    echo rwmb_meta( 'mb_membership', ['object_type' => 'user'], get_current_user_id() )
    ?>

    It can't display anything. Could you please let me know what's going wrong? Thank you.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.