Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Result BP Xprofile fields
This topic contains 2 replies, has 2 voices, and was last updated by esteves.klein19 3 years, 4 months ago.
- AuthorPosts
- June 26, 2020 at 9:24 pm #28116
Please, I need help to present the custom fields of “BP Xprofile” in the result.
Example: {titlefield} {cellphone}June 29, 2020 at 9:56 am #28133Hi!
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!
Best,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; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
July 17, 2020 at 1:53 am #28532Perfect! Great idea!
Thank you - AuthorPosts
You must be logged in to reply to this topic.