xprofile_get_field( int|object $field, int|null $user_id = null, bool $get_data = true )

Get a profile field object.

Parameters Parameters


(int|object) (Required) ID of the field or object representing field data.


(int|null) (Optional) ID of the user associated with the field. Ignored if $get_data is false. If $get_data is true, but no $user_id is provided, defaults to logged-in user ID.

Default value: null


(bool) (Optional) Whether to fetch data for the specified $user_id.

Default value: true

Top ↑

Return Return

(BP_XProfile_Field|null) Field object if found, otherwise null.

Source Source

File: bp-xprofile/bp-xprofile-functions.php

function xprofile_get_field( $field, $user_id = null, $get_data = true ) {
	if ( $field instanceof BP_XProfile_Field ) {
		$_field = $field;
	} elseif ( is_object( $field ) ) {
		$_field = new BP_XProfile_Field();
		$_field->fill_data( $field );
	} else {
		$_field = BP_XProfile_Field::get_instance( $field, $user_id, $get_data );

	if ( ! $_field ) {
		return null;

	return $_field;

Top ↑

Changelog Changelog

Version Description
2.8.0 Added $user_id and $get_data parameters.
1.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.