Result BP Xprofile fields

This topic contains 2 replies, has 2 voices, and was last updated by esteves.klein19 esteves.klein19 3 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #28116
    esteves.klein19
    esteves.klein19
    Participant

    Please, I need help to present the custom fields of “BP Xprofile” in the result.
    Example: {titlefield} {cellphone}

    #28133
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    It could be possible, but only programatically. I found a code that I suggested about two years ago about a similar query, that might be useful in your case as well.

    You can enter the profile field names to the $fields variable (line 3), comma separated, and then I believe the code will print them line by line with their labels. I don’t know if this works anymore, buddypress xprofile fields may have changed their API since then.

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter('asp_results', 'asp_display_all_fields_user_res', 10, 4);
    function asp_display_all_fields_user_res($results, $sid, $is_ajax, $args) {
      $fields = 'Name,Phone,Test field';  // Enter the fields here, separated by comma
      
      // -- DO NOT CHANGE BELOW THIS LINE --
      foreach ($results as $k=>&$r) {
        if ( $r->content_type == 'user' ) {
          $f = array();
          $_fields = asp_get_extended_fields($r->id, $fields);
          foreach ($_fields as $kk => $vv) {
            $f[] = '<strong>' . $vv['name'] . '</strong>: '. $vv['value'];
          }     
          if ( count($f) > 0 )
            $r->content = implode('<br>', $f);
        }
      }
      return $results;
    }
    function asp_get_extended_fields( $user_id, $allowed_fields ) {
    	$allowed_fields = str_replace('  ', ' ', $allowed_fields);
    	$allowed_fields = str_replace(array(', ', ' ,', ' , '), ',', $allowed_fields);
    	$allowed_fields = explode(',', $allowed_fields);
    	$fields = array();
    	/* Get User Extended Data */
    	$r = bp_parse_args( array(), array(
    		'profile_group_id' => 0,
    		'user_id'          =>  $user_id
    	), 'bp_xprofile_user_admin_profile_loop_args' );
    	$i = 0;
    	if ( bp_has_profile( $r ) ) {
    		
    		while ( bp_profile_groups() ) {
    			bp_the_profile_group(); 
    			
    			while ( bp_profile_fields() ) {
    				bp_the_profile_field();
    				$field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() );
            $f_name = bp_get_the_profile_field_name();
            if ( !in_array($f_name, $allowed_fields) )
              continue;
    				$fields[$i]['name'] = $f_name;
    				$fields[$i]['id'] = bp_get_the_profile_field_input_name();
    				$fields[$i]['value'] = bp_get_the_profile_field_edit_value();
    				$i++;
    			}
    		}		
    	}
    	return $fields;
    	
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #28532
    esteves.klein19
    esteves.klein19
    Participant

    Perfect! Great idea!
    Thank you

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.