[buddypress-dev] Getting Custom Field Values

David J. Bisset dbisset at dimensionmedia.com
Wed Jun 11 12:23:52 GMT 2008


Hi all,

I wanted to share this function I built in  
bp-xprofile-templatetags.php which allows one to grab custom profile  
values.

function get_field_value($fieldname, $output_field_name = false,  
$dropdown = false) {
	global $profile_template;
	foreach ($profile_template->groups as $group) {
		foreach ($group->fields as $field) {
			if ($field->name == $fieldname && $field->data->value != '') {

				if ($output_field_name) {
					return $field->name . ": " . $field->data->value;
				} else {
					return $field->data->value;
				}
			}
		}
	}
}

This works for single-value profile values such as textboxes and  
select dropdowns. Looking for ways to improve the function when it  
comes to multiple-value values which would look like this in the  
output (assuming the values "online" and "local" are selected):

a:2:{i:0;s:6:"Online";i:1;s:5:"Local";}

Regardless, the above function I hope is a step in the right direction.

-- 
David Bisset
Director of Web Development
Dimension Media, Inc.
www.dimensionmedia.com
http://www.linkedin.com/in/davidbisset



More information about the buddypress-dev mailing list