Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display something different to male and female members based off xprofile values

  • @markob17

    Participant

    Hi,

    I’m trying to display something different to male and female members on my site based off their selected xprofile value (created a gender field with male and female values) but can’t figure it out. I pieced the below code together after Googling around for awhile. I thought it would work but it simply echos ‘male’ twice on the page instead of echoing ‘male’ to male members and ‘female’ to female members. There probably is a more efficient way to achieve this and I’m not even sure I’m on the right track. Any ideas? Much appreciated!

    <?php
    global $wpdb;
    $custom_value_male = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Male'");
    $custom_value_female = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = 2 AND value = 'Female'");
    
    if( $custom_value_male ) {
    echo 'male';
    
    } else if( $custom_value_female ) { 
    echo 'female';
    
    } else {
    null;
    
    }
    ?>

    Best Regards,
    Mark

Viewing 1 replies (of 1 total)
  • @markob17

    Participant

    Not sure what I was going for before but using the below code seems to do the trick, and it outputs things in a more efficient manner. If anybody knows an even cleaner way to do this, please let me know.

    <?php
    global $bp;
    $args = array( 'field' => 'Gender', 'user_id' => bp_loggedin_user_id() );
    $gender = bp_get_profile_field_data($args);
    
    if ( $gender == "Female" ):
    echo 'female';
    
    elseif ( $gender == "Male" ):
    echo 'male';
    
    endif;
    ?>

    Regards,
    Mark

Viewing 1 replies (of 1 total)
  • The topic ‘Display something different to male and female members based off xprofile values’ is closed to new replies.
Skip to toolbar