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.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
The topic ‘ [Resolved] How do you get all the available values for a xprofile field (checkbox or select’ is closed to new replies.