Ranges

BP Profile Search Ranges

  • Author
    Post
  • #11899 Reply
    Alex
    Guest

    Hi,

    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,
    Alex

    #11900 Reply
    andrea
    Plugin Author

    Hi 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.

    #11901 Reply
    Alex
    Guest

    Hi 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,
    Alex

    #11902 Reply
    andrea
    Plugin Author

    Yes, 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');
    
    #11903 Reply
    Alex
    Guest

    Hi 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,
    Alex

    #11904 Reply
    andrea
    Plugin Author

    Hi Alex,

    The IF condition is:

    	if ($f->code == 'field_6')
    

    not:

    	if ($f->code == 'field_6_range')
    

    Can you try changing that line?

    #11905 Reply
    Alex
    Guest

    Hi Andrea,

    That worked, it was the field name that was causing the issue.

    You are a star!

    Thanks,
    Alex

    #11907 Reply
    andrea
    Plugin Author

    You’re welcome!

Reply to: Ranges
My Information