Showing connected users on a post template made by a different user

Support MB User Meta Showing connected users on a post template made by a different user

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36191
    YasmineYasmine
    Participant

    Hey again, I am trying to display connected users on a single elementor template. The author selects the sometimes multiple users to show using the user custom field. I want to create a loop to display the connected users.

    Only problem is I don't know how to approach this or even which data to populate the loop with. I want to show the selected users name, photo and a custom field that is saved to their profile.

    Do I need a shortcode for this? If so, how do I make one?

    add_shortcode( 'display_coauthors', function() {
    $post_id = get_post_field( 'post_id', get_queried_object_id() );
    $co_author = rwmb_the_value( 'academicuser_contributor', ['object_type' => 'user'], ['display_field' => 'custom_avatar'] ); //academicusercontributor is the custom field id .. do I need to use the user fields id instead??
    $output = $co_author;
    return $output;
    });
    #36219
    Long NguyenLong Nguyen
    Moderator

    Hi Yasmine,

    If you are using the field user to set multiple authors for the post, you can follow the documentation to get user IDs and author meta.
    https://docs.metabox.io/fields/user/#template-usage
    https://docs.metabox.io/extensions/mb-user-meta/

    For example:

    <?php $user_ids = rwmb_meta( 'field_user_id', '', get_queried_object_id() );
        foreach ( $user_ids as $user_id ) {
            $co_author = rwmb_the_value( 'user_meta_id', ['object_type' => 'user'], $user_id );
        }
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.