Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display a value of a particular custom profile field

  • Avatar of arkokoley
    arkokoley
    Participant

    @arkokoley

    Hi, I want to display the value of a custom profile field in a custom menu in my theme. I have created a custom profile field “Class” whose value can be selected as “X”, “XI”, or “XII”. This value of Class varies from member to member and I want to display it in my navbar that the person belongs to this “Class”. Like for example,

    Gaurav Koley, X

    in the theme’s navbar.

    Any ideas how to do this? I apologize if this is a stupid question, but I’m a newbie.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Avatar of Fee
    Fee
    Participant

    @wdfee

    bp_member_profile_data( ‘field=the field name’ ); –> try bp_member_profile_data( ‘field=Class’ );

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    @arkokoley, @wdfee

    works better by using  both xprofile_get_field_data and a user_id !

        $user_id = bp_get_member_user_id();

    // if “Class” is the field name
    $mystuf = xprofile_get_field_data( ‘Class’, $user_id );

    Application example here:

    http://wpmu.org/buddypress-profile-data-on-multisite/

    Avatar of arkokoley
    arkokoley
    Participant

    @arkokoley

    @chouf1, @wdfee

    Thanks for the help but neither code is useful for me.

    bp_member_profile_data( ‘field=Class’ ); returns an error stating unexpected “=”

    @chouf1, your code doesn’t return anything atleast in my case. Any ideas what I did wrong? This is what I coded:
    <?php
    global $current_user;
    $user_id = bp_get_member_user_id();
    $class = xprofile_get_field_data( ‘Class’, $user_id );
    echo $class;
    ?>

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    @arkokoley,

    you coded it wrong, and we don’t know where you coded it. The mentionned elements i give you should be into a function, and depending where it must appear, you have to add or alter an existing filter.

    I can’t help you more because you don’t give any details for what you exactly want to do so , on witch theme (name?) and BP version you use.

    Displaying values on the theme’s navbar‘ is not enough, sorry !

    Avatar of giannisff
    giannisff
    Participant

    @giannisff

    <?php if ( $data = bp_get_profile_field_data( ‘field=class’ ) ) : ?>
    ” > <?php bp_profile_field_data(‘field=class’);?> <?php bp_profile_field_data(‘field=Name’);?>
    <?php endif;?>
    I’m not sure that it’s work’s for you (where do you want to take this). This code just check if your profile field has value and appear this value and the name-value. (clikable). I hope it helps you.

    Avatar of arkokoley
    arkokoley
    Participant

    @arkokoley

    This is the site. Site

    @chouf1, I use WordPress-Bootstrap by 320press. In the circled tab, i want to display the class of the student. Also depending on the Class menus with different elements will be put in that sidebar.

    How do I do this? Even if I could compare the value of the profile field it would do.
    For example,

    if( bp_profile_field_data(‘field=class’);==X)
    <do something here.>

    something like this.

    Avatar of arkokoley
    arkokoley
    Participant

    @arkokoley

    I coded it directly into the theme’s header, where the rest of the sidebar is. Should I do something else? I’m a newbie to PHP, though I know C++ to some extent.

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    here’s a untested function. Would perhaps output the member name and the Class he belongs

    function bpfr_member_class($myinfo) {
    global $bp;

    $user_id = bp_get_member_user_id();

    $membername = xprofile_get_field_data( ‘Name’, $user_id );
    $data = xprofile_get_field_data( ‘Class’, $user_id );

    if( $data )
    $myinfo = ‘<div class=”myinfo”>’. $membername.’ CLASS: ‘. $data .’</div>’;

    return $myinfo;
    }

    I’m a newbie to php (me also) – this is not an excuse especially when you’re going to code on the fly without reading documentation and forum topics.

    What you doing wrong ;-)
    - You’re coding directly into your theme
    - You don’t read the answers you receive and you don’t answer the questions.

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.