BP_XProfile_ProfileData::get_fielddataid_byid( int $field_id, int $user_id )
Get the user’s field data id by the id of the xprofile field.
Description
Parameters
- $field_id
-
(Required) Field ID being queried for.
- $user_id
-
(Required) User ID associated with field.
Return
(int) $fielddata_id
Source
File: bp-xprofile/classes/class-bp-xprofile-profiledata.php
public static function get_fielddataid_byid( $field_id, $user_id ) {
global $wpdb;
if ( empty( $field_id ) || empty( $user_id ) ) {
$fielddata_id = 0;
} else {
$bp = buddypress();
// Check cache first.
$cache_key = "{$user_id}:{$field_id}";
$fielddata = wp_cache_get( $cache_key, 'bp_xprofile_data' );
if ( false === $fielddata || empty( $fielddata->id ) ) {
$fielddata_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ) );
} else {
$fielddata_id = $fielddata->id;
}
}
return (int) $fielddata_id;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.6.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.