BuddyDev

Search

[Resolved] How do you get all the available values for a xprofile field (checkbox or select

  • Participant
    Level: Enlightened
    Posts: 40
    Jaume Aragay on #5221

    I see there is a function to get the selected values from a checkbox field but how do you get all the available values for a xprofile field (checkbox or select field)? Like having Barcelona, Paris, London, NY as available city values. How do you get that list of cities?
    I found a post on getting some of the xprofile values but didn’t find a way to get all the available values for a field.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #5222

    Hi Jaume,

    Welcome back.

    It’s a good question. Since there does not exist any functions, I wrote one for you

    
    
    /**
     * @param int $field_id Field ID
     *
     * @return array of options
     */
    function buddydev_xprofile_get_field_options( $field_id ) {
    
    	$field = xprofile_get_field( $field_id );
    
    	$options = $field->get_children();
    
    	return wp_list_pluck( $options, 'name' );
    
    }
    
    

    You can put this function in your bp-custom.php or functions.php and then call it like this

    
    
    print_r( buddydev_xprofile_get_field_options ( 17 ) );
    
    

    17 is field id. Change it with your own field. In case of non multi field, It will give you an empty array.

    Hope that helps.
    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 40
    Jaume Aragay on #5229

    Thank you! It does solve it! 😉

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #5233

    Hi Jaume,
    I am glad it did 🙂

The topic ‘ [Resolved] How do you get all the available values for a xprofile field (checkbox or select’ is closed to new replies.

This topic is: resolved