BP Profile Search › Converting fields
-
AuthorPost
-
AlexGuest
Hi Andrea,
I have a height field which is of type dropdown as the user can only select one.
When it comes to the search is there a way to convert this field into a range so the user can set a minimum and maximum to search between.
Thanks,
AlexandreaPlugin AuthorHi Alex,
Sorry for the late reply!
You can try this:
1. Add this code to your bp-custom.php file:
add_filter ('bps_xprofile_format', 'convert_format', 10, 2); function convert_format ($default, $field_id) { // replace 143 with your field ID if ($field_id == 143) return 'decimal'; return $default; }
2. Go back to your search form edit page, and select the new option range as your Search Mode
3. Now the search form should display two input boxes instead of a drop-down menu.
AlexGuestHi Andrea,
Thanks for the reply and it does convert them to two blank input boxes, what I actually need is to have to two drop down select fields that populate from the profile field height. There is a range from 4′ to 6’7″ and I need those values pulled into the select fields.
Thanks,
AlexandreaPlugin AuthorHi Alex,
You can add some more code to bp-custom.php:
add_action ('bps_field_before_search_form', 'change_display'); function change_display ($f) { // replace 143 with your field ID if ($f->code == 'field_143' && $f->display == 'range') { $f->display = 'range-select'; $f->options = array ('' => '') + $f->options; } }
Together with the previous code, this should do what you need.
AlexGuestHi Andrea,
When I try that it throws up a critical WordPress error.
My code is this:
add_filter (‘bps_xprofile_format’, ‘convert_format’, 10, 2);
function convert_format ($default, $field_id)
{
// replace 143 with your field ID
if ($field_id == 20) return ‘decimal’;
return $default;
}add_action (‘bps_field_before_search_form’, ‘change_display’);
function change_display ($f)
{
// replace 143 with your field ID
if ($f->code == ‘field_20’ && $f->display == ‘range’)
{
$f->display = ‘range-select’;
$f->options = array (” => ”) + $f->options;
}
}The field is set to a dropdown and the id of the input is “field_20_range”.
Not sure what’s going on, any help would be great.
Thanks,
AlexandreaPlugin AuthorHi Alex,
A few suggestions:
1. Please make sure the code is copied correctly, especially the quote characters should be the same as in my original code above;
2. Try to recover the full error message, you could temporarily set WP_DEBUG to true to see the error message (https://wordpress.org/documentation/article/debugging-in-wordpress/)
3. If everything else fails, I can have a look at your testing site to better understand what’s happening.
-
AuthorPost