How to query for user profile fields of the author of the current post?

Support › MB Views › How to query for user profile fields of the author of the current post?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36048
    EddyPiVEddyPiV
    Participant

    Hi,

    I have defined user profile fields.
    Now I want to display these user profile fields for the author of the current post. They will be shown through a shortcode in the sidebar.

    I managed to get it all working properly, except for a minor detail. I know how the get the author's user id, I know how to get the user profile fields, but what I don't know is the code to pass on the author's user id to the query.

    This is what I have:

    <div>
    {% set post = mb.get_post( ) %}
    
    {{ post.post_author }}
    
    {% set user = mb.get_userdata( 583 ) %}
    <strong>Name:</strong> {{ user.user_login }}
    <strong>Age:</strong> {{ user.age }}
    <strong>Social status:</strong>{{ user.social_status }}
    <strong>Likes:</strong>{{ user.likes}}
    <strong>Experience:</strong>{{ user.experience }}
    <strong>Limits:</strong>{{ user.limits }}
    <strong>Other:</strong>{{ user.other }}
    
    [su_button url={{ user.your_shared_folder }} target="_blank" style="default" background="#da4453" color="#FFFFFF" size="5" wide="no" center="yes" radius="0" icon_color="#FFFFFF" text_shadow="none" ]Shared Folder[/su_button]
    </div>

    So for now I just put hardcoded the author's user id, to test the rest.
    But I'm looking for that "bridge code".

    Can you pls help?

    #36051
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Since post.post_author return the post author ID, you can pass it to the function get_userdata(). Like this

    {% set user = mb.get_userdata( post.post_author ) %}

    #36054
    EddyPiVEddyPiV
    Participant

    I think I tried that, but didn't work. I must have made a mistake then, as it works now nicely.

    Thanks Long

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