检查当前用户是否在配置文件字段中具有特定值

时间:2014-02-22 12:28:08

标签: php buddypress

我有一个有zeypress的网站,我需要检查当前用户是否在特定字段上具有特定值

我正在尝试这个,但它无法正常工作

 <?php 
$data= bp_profile_field_data( array('user_id'=>get_current_user_id( 'ID' ))); 
 if($data=='Funny Guy') {
  echo 'yes';
} else {
  echo 'no';
}
?>

任何提示为什么?

1 个答案:

答案 0 :(得分:1)

请尝试使用bp_get_profile_field_data,并提供所需字段的名称。所以:

$args = array(
    'field'   => 'Your field name', // Exact field name or field ID.
    'user_id' => bp_loggedin_user_id() // ID of logged in user
);

$data = bp_get_profile_field_data( $args ); 
if ( $data == 'Funny Guy' ) {
    echo 'yes';
} else {
    echo 'no';
}