BP Profile Search › Ranges
-
AuthorPost
-
Alex
GuestHi,
I’m using your plugin which is great but when I have a field that is a range there is no way to enter default values.
For example, I’m searching based on age and need to set the min and max fields.
Thanks,
Alexandrea
Plugin AuthorHi Alex,
You can set the age range default values adding this code to your bp-custom.php file:
add_action ('bps_field_before_search_form', 'set_defaults'); function set_defaults ($f) { if ($f->code == 'field_54') { $f->value['min'] = 18; $f->value['max'] = 99; } }
Replace 54 with the actual field ID of your date field.
Alex
GuestHi Andrea,
Thanks for the quick response, I added the file bp-custom.php to my plugin directory but it doesn’t work. I’m using BuddyBoss, is that an issue?
Thanks,
Alexandrea
Plugin AuthorYes, BuddyBoss is a bit different. Try adding this line as the first line in the above code:
add_action ('bp_ps_field_before_search_form', 'set_defaults');
Alex
GuestHi Andrea,
I tried that but still no luck so I thought I would put an “echo” into the function and it doesn’t even call it with the update.
So I changed it back to “add_action (‘bps_field_before_search_form’, ‘set_default’);” and I can now see that the function returns my echo so I know that’s working.
The only thing is it’s not updating the input values, I have included the html for the input field and the function below:
<input type=”number” id=”field_6_range” name=”field_6_range[min]” value=””>
add_action (‘bps_field_before_search_form’, ‘set_default’);
function set_default ($f)
{
if ($f->code == ‘field_6_range’) // replace 34 with your field ID
{
// assign the default value
{
$f->value[‘min’] = 18;
$f->value[‘max’] = 99;
}
}
echo “Hello!”;
}So to me it looks like the code within the function isn’t working.
Thanks,
Alexandrea
Plugin AuthorHi Alex,
The IF condition is:
if ($f->code == 'field_6')
not:
if ($f->code == 'field_6_range')
Can you try changing that line?
Alex
GuestHi Andrea,
That worked, it was the field name that was causing the issue.
You are a star!
Thanks,
Alexandrea
Plugin AuthorYou’re welcome!
-
AuthorPost