Skip to:
Content
Pages
Categories
Search
Top
Bottom

Check value of profile field – displaying images in profile *if*


  • Number_6
    Participant

    @number_6

    Hello,
    I’ve looked high and low to find out how to use PHP to check if a custom profile field (dropdown) value is x, y, and z. My purpose for this is to display a corresponding image for each possible choice.
    I’m sure others would be looking for such a snippet like I was.

    Cheers

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

  • shanebp
    Moderator

    @shanebp

    It depends on where you want to do it.

    On a profile page:

    $some_field = bp_get_member_profile_data( 'field=Name of Field' );
    if( !empty( $some_field ) ) {
         if( $some_field == 'x') 
            echo 'x'; 
         elseif( $some_field == 'y') 
            echo 'y'; 
         else
            echo 'z'; 
    }

    On the all members page:

    $user_id = bp_get_member_user_id();
    $some_field = xprofile_get_field_data( 'Name of Field', $user_id, $multi_format = 'comma' );
    if( !empty( $some_field ) ) {
    //etc. 

    Number_6
    Participant

    @number_6

    Thanks @shanbp
    May I ask what do I do with the instances of $some_field in your snippet? I see it in BP and WP’s documentation. I know $someword takes the place of the name of something, but that’s about it.


    shanebp
    Moderator

    @shanebp

    $some_field is a variable that you create.
    Its value is whatever you assign to it, iow. whatever is to the right of the = sign.
    The name of the variable can be whatever you want, as long as it’s unique.
    It could be $bongos_ahoy or $smelly_dog, etc.
    This is basic coding and not really appropriate for this forum.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Check value of profile field – displaying images in profile *if*’ is closed to new replies.
Skip to toolbar