Skip to:
Content
Pages
Categories
Search
Top
Bottom

Displaying logged in user profile field value outside the loop

  • @ks-webdesignercom

    Participant

    Hi, in my header file I would like to display the value of one of my xprofile fields for the currently logged in user. The field ID is “11”.

    Basically I want an output that says something like:
    “Hi [username] – Account Type: [value of field 11]”

    No problem getting the username, but I just can’t seem to access the value of field 11?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @henrywright-1

    Member
    <?php
    echo 'Hi ' . bp_core_get_username( bp_loggedin_user_id() ) . ' – Account Type: ' . bp_get_profile_field_data( 'field=VALUE' );
    ?>

    Note: VALUE should be the exact name of the field you want to use.

    @ks-webdesignercom

    Participant

    Thanks, it kinda works. Only if I’m viewing my profile page. If I view any other page on the site it doesn’t find the value and just displays: Account:

    I am trying to run this in the header.php file of my template…

    @henrywright-1

    Member

    Ah yes of course.

    Replace:

    bp_get_profile_field_data( 'field=VALUE' )

    With

    xprofile_get_field_data( 'field=VALUE', bp_loggedin_user_id() )

    @ks-webdesignercom

    Participant

    Thanks again, just needed one slight tweak. Final code is as follows:

    <?php echo 'Hi ' . bp_core_get_username( bp_loggedin_user_id() ) . ' – Account Type: ' . xprofile_get_field_data( 'FIELD NAME OR ID', bp_loggedin_user_id() ); ?>

    Didn’t need the “field=” for xprofile… Works using either the field name or the id.

    @enrons

    Participant

    Hi .. ,

    for over 6 months i search for this function.

    I need a function to display: “bp_get_member_profile_data”
    in activity-stream for each invidually user in activity-stream !!!!!!!!!!!!!

    Yes, I know the different with bp_get_member_profile_data and xprofile_get_field_data !
    It´s all crazy, but whatever.

    If i put the this in custom-function.php, in example:

    ————————-
    function show_extra_profile_fields() {
    global $bp;
    $myfield = xprofile_get_field_data( ‘City’, $bp->loggedin_user->id );
    echo $myfield;
    }
    add_action( ‘my_test_action’, ‘show_extra_profile_fields’ );

    —————–

    And put this Code in activty – entry.php

    <?php do_action( ‘my_test_action’, ‘show_extra_profile_fields’ ); ?>

    ——————–

    It shows the City, but in all activies it shows my City !
    Also logically, because i say: –>loggedin_user

    But I need the function to display the invidually City for User in entry.php !!

    Please Help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying logged in user profile field value outside the loop’ is closed to new replies.
Skip to toolbar