Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get select options from xprofile fields

  • @stegtflesk

    Participant

    Hi, how do i get all the select options from a custom profile fields?
    I made a select field with 3 options. And i want to get these options.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @danbp

    Participant

    @stegtflesk,
    depends where you want to show these option values : in or outside of a profile.

    If in, you create filter function containing at least

    function function_name() {
    $val = ( 'FIELD_NAME', $user_id ); // custom field name; case sensitive
    
    if($val == 'option_1') : // option name
    //do something...
    endif;
    
    if($val == 'option_2') :
    // do something...
    endif;
    
    //if etc
    }
    add_filter( 'my_custom_filter', 'function_name', 9, 2 ); // , priority, $val

    and in the template, you add this filter at the appropriate place, by using
    do_action( 'my_custom_filter' );

    If ouside of profile, you need a user_id

    
    $user_id = bp_get_member_user_id();
    $val = xprofile_get_field_data( 'field_name', $user_id );
    
    if($val == 'option_1')
    do something
    
    if($val == 'option_2')
    do something
    
    return $val;
    
    add_filter....

    In both case, you can use an existing BP template filter or a custom one.

    Hope this help.

    @stegtflesk

    Participant

    Thx for the replay, but its not the value of the field i need, but the array of options i have created in the wp backend.

    Ex.

    I have created a new profile field in the “User->profile fields” page in the wp backend. Calling it eyecolour.

    So i select the field to be a “select, dropdown” (still in the wp backend). I enter an array of eyecolours as options and saves the field and set the default colour as green. I am now able to extract the value of the field as you shown above. But i wanto get the full array of all the options of the field pref. as and array. Then i would be able to create the dropdown, dynamically in the frontend, using the options i allready created.

    psudocode example (i know its the wrong functions, its just to show the logic):

    $selectedOption = get_profile_field(‘eyecolor’);
    $possibleOptions = get_profile_field_options(‘eyecolor’); //this function i need!! 😛

    foreach ($possibleOptions as $option) {

    if ($option == $selectedOption) {

    echo ‘<option selected value=”‘.$option.'”>’.$option.'</option>’;

    } else {

    echo ‘<option value=”‘.$option.'”>’.$option.'</option>’;

    }

    hope this makes sense 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get select options from xprofile fields’ is closed to new replies.
Skip to toolbar