Best way to display user fields

Support MB User Meta Best way to display user fields

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39497
    JorgeJorge
    Participant

    I've got a site that is using GeneratePress/GenerateBlocks, which would be the best way to display current user meta fields?

    My initial thinking was a View, but it could make things a bit complex for the client, since the fields they want to display are within a Page/Block layout.

    Then, I remembered that there's a Shortcode feature however I'm not entirely sure how to display a single field.

    What I've done is create a Field Group ('User Profile Fields', that has a post ID of 356) to be used on the location "User". Inside is a Text field that has the ID of 'phone_field'.

    So I thought to place the shortcode in the Page editor/Gutenberg-default WP editor like this:
    [rwmb_meta id="phone_field"] which didn't work. Reading the documentation, it would help to add the object_id so [rwmb_meta id="phone_field" object_id="356"] but that didn't work either.

    Am I using the shortcode settings wrong? Are there any better ways to display User Meta fields?

    #39509
    PeterPeter
    Moderator

    Hello Jorge,

    To display the user meta field with shortcode, you need to add the attribute object_type="user" to the shortcode. For example:

    [rwmb_meta id="phone_field" object_id="15" object_type="user"]

    where 15 is the user ID, not the post ID of the field group. Please read more on the documentation https://docs.metabox.io/extensions/mb-user-meta/#getting-field-value

    #39519
    JorgeJorge
    Participant

    Ah! That explains a lot Peter, thank you.

    Setting the User ID like that will display only the user that matches the ID of "15", is it possible to have the shortcode display it to the -current- logged-in user? Or do I need to set up a helper function to access it from there?

    #39558
    PeterPeter
    Moderator

    Hello Jorge,

    To get the current logged-in user, you have to use the code. The shortcode does not support an attribute to get the current logged-in user. Please refer to this topic https://support.metabox.io/topic/how-can-i-output-a-group-field-for-current-users/#post-35544

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