How to display custom user meta field on website?
Support › MB User Meta › How to display custom user meta field on website?Resolved
- This topic has 12 replies, 3 voices, and was last updated 2 years, 1 month ago by
leenn.
-
AuthorPosts
-
June 11, 2021 at 2:08 PM #28849
Danny
ParticipantI'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.
June 11, 2021 at 4:18 PM #28851Long Nguyen
ModeratorHi Danny,
You need to pass two attributes
object_type
andobject_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
June 12, 2021 at 4:10 PM #28861Danny
ParticipantHey 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.
June 13, 2021 at 6:24 PM #28871Long Nguyen
ModeratorHi 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
June 13, 2021 at 8:07 PM #28872Danny
ParticipantHmm.. 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.
June 14, 2021 at 12:29 PM #28882Long Nguyen
ModeratorHi,
Meta Box is a developer tool so you need to have basic coding knowledge to do more advanced cases with Meta Box.
June 14, 2021 at 4:53 PM #28890Danny
ParticipantI 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?
June 14, 2021 at 10:07 PM #28894Long Nguyen
ModeratorHi,
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/June 15, 2021 at 9:41 AM #28898Danny
ParticipantUnfortunately, 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; }
June 15, 2021 at 11:21 AM #28902Long Nguyen
ModeratorHi,
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.
June 15, 2021 at 1:59 PM #28905Danny
ParticipantHey 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?
June 15, 2021 at 11:18 PM #28916Long Nguyen
ModeratorHi,
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.
March 9, 2023 at 11:07 AM #40905leenn
ParticipantHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.