Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: How do you list all of the values in a profile field?


plrk
Participant

@plrk

I’m not sure what you want to do, but with this code, you can get a list of the options and the amount of users who have selected the option. Note: for selectbox and radio fields only.

$field_id = 1; // this should be the id of the
// field you want, see your wp_bp_xprofile_fields
// database table to find it

global $wpdb;

$sql = "SELECT value FROM {$wpdb->base_prefix}bp_xprofile_data WHERE field_id = {$field_id} ORDER BY id DESC";
$result = $wpdb->get_col($wpdb->prepare($sql));
foreach($result as $row){
if(strlen($row) > 0){
$values[$row]++;
}
}
$i = 0;
foreach($values as $key => $value){
$i++;
if($i != 1){
echo ", ";
}
echo $key . "(" . $value . ")";
}

Skip to toolbar