How to show buddypress profile information at the top of a users store?

Hi, how do I show the buddypress user profile information such as their picture and their bio at the top of their store/shop?

  • Vaughan
    • Support/SLS MockingJay

    Hi @urbanlymedia

    Thanks for the post.

    I think you would need to modify your templates to pull in the information from the buddypress profile & include it in the page itself. depending on exactly where you want it displayed,

    i'm not sure of exact code. but something like this in your template file, or in the themes header maybe (if you want it displayed on every page), the code might be slightly different depending on whether it's inside or outside of the loop.

    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    bp_profile_field_data( array('user_id'=>$current_user_id,'field'=>'bio' ));

    hope this helps

    thanks

  • Vaughan
    • Support/SLS MockingJay

    hiya

    you are correct. you would need to get the store owners ID instead

    however I don't think there's a specific key for that.

    maybe a crafty SQL query, you could grab the store name & then get the info from

    wp_blogs table

    or with buddypress bp_user_blogs table

  • Vaughan
    • Support/SLS MockingJay

    hiya

    it would be something like

    <?php
    $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->bp_user_blogs_blogmeta WHERE meta_value = bloginfo('name')" );
    
    $owner_id = $wpdb->get_var( "SELECT user_id FROM $wpdb->bp_user_blogs WHERE blog_id = $blog_id" );
    
    $owner_bio = bp_profile_field_data( array('user_id'=>$owner_id, 'field'=>'<your bio fieldname>' ));
    
    echo $owner_bio;
    ?>

    something like that, there could be an easier way, I would put the query into a function in functions.php then you just need to call the function from the theme to get the results.

    hope this helps

  • Vaughan
    • Support/SLS MockingJay

    hiya

    put this in your themes functions.php

    function get_BPOwnerID($blogname) {
    $blog_id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->bp_user_blogs_blogmeta WHERE meta_value = $blogname" );
    
    $BPOwnerID = $wpdb->get_var( "SELECT user_id FROM $wpdb->bp_user_blogs WHERE blog_id = $blog_id" );
    
    $owner_bio = bp_profile_field_data( array('user_id'=>$owner_id, 'field'=>'<your bio fieldname>' ));
    
    return (int) $BPOwnerID;
    }
    
    function ownerInfo($ownerID, $field) {
    $ownerInfo = bp_get_profile_field_data( array(
        'field'   => $field,
        'user_id' => $ownerID)
    );
    
    return $ownerInfo;
    }

    then in your themes template, (depending on where you want it), possibly header.php

    <?php
    $ownerID = get_BPOwnerID(bloginfo( 'name' ));
    
    echo 'Name: ' . ownerInfo($ownerID, 'name');
    echo 'Bio: ' .  ownerInfo($ownerID, 'bio');
    echo 'Avatar: ' . get_avatar($ownerID);
    ?>

    I haven't tested any of this, so it may not work out of the box. you'll need to change the names to match your bp profile fieldnames you created. such as bio if you called it biography, you would change bio above to biography.

    Obviously you may have to add a bit of styling to the above, such as a div class or something.

    there could be an easier way of doing it, i'm not sure. it's easier from within the bp_members_loop, but from what you asked, you would need to get it from outside the loop itself.

    hope this helps.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.