• Resolved Gomle

    (@gomle)


    Hi.

    I am trying to do an simple if/else check to see if the user has filled out any values.

    What do I need to write to get the content in the fields to check?

    E.g.

    if (!empty($field1) && !empty($field2) && !empty($field3)) {
    // do this
    } else {
    // do this
    }
Viewing 1 replies (of 1 total)
  • Plugin Author Brajesh Singh

    (@sbrajesh)

    Hi Gomle,
    My apologies for the delayed reply.

    In order to do this you will need field ids. Here I am assuming that you have the field ids and user id for which data is being fetched.

    I am using dummy values for them.

    
    
    	// change the ids.
    	$field_1_id = 1;
    	$field_2_id = 5;
    	$field_3_id = 7;
    	// may be change user id?
    	$user_id = get_current_user_id();
    
    	$field_1 = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_1_id, $user_id ) );
    	$field_2   = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_2_id, $user_id ) );
    	$field_3   = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_3_id, $user_id ) );
    
    

    With the above code in place, you can apply your condition.

    I avoided using xprofile_get_field_data as it gives filtered data which may not be empty for some fields even if the data is not present.

    Regards
    Brajesh

Viewing 1 replies (of 1 total)
  • The topic ‘Get the field value’ is closed to new replies.