• Carsten Lund

    (@carsten-lund)


    Hi Andrea, I have followed your instructions to modify the range display, by adding this code to bp-custom.php, I also replaced the field number, but no action, the drop down doesn’t show.

    Just to clarify, how do I find the correct corresponding field number; is it the field number in the search field form, counting fields from the top, or the field number in the profile fields?

    Does it work with age range as well?

    Regards
    Carsten

    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
        if ($f->code == 'field_4' && $f->display == 'range')
        {
            $f->display = 'range-select';
            $range = range (18, 99);
            $f->options = array ('' => '') + array_combine ($range, $range);
        }
    }
    
Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hello Carsten,

    You can see the field ID if you go to the Users -> Profile Fields admin page, and use the field Edit button.

    If you click the button, you go to the Edit Field page and you can see the field ID contained in the URL. If you hover on the button with your mouse, you reveal the URL, and see the field ID, without actually going to the Edit Field page.

    Please note that the code you are using only works with the age range search mode, and with the bps-form-default template.

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, hmmm, I can’t get it to work, just to be sure, the code should be field_2389 like stated, not field_id=2389?

    View post on imgur.com

    View post on imgur.com

    I use the x-profile fields to/from type, one with age range and one only range. Is it possible to make it work with the range search mode as well?

    Regards
    Carsten

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Carsten,

    Probably you are not using the built-in bps-form-default template. Could you please go to your Users -> Profile Search admin page and paste whatever is displayed under the Template column?

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi again, yes I am using the default template

    View post on imgur.com

    Thread Starter Carsten Lund

    (@carsten-lund)

    Should it work on both age range and range, and, in this case, should I add the code snippet for both by duplicate this with each id?

    Thread Starter Carsten Lund

    (@carsten-lund)

    These are my profile fields type with corresponding search mode

    View post on imgur.com

    View post on imgur.com

    View post on imgur.com

    Plugin Author Andrea Tarantini

    (@dontdream)

    Carsten,

    Try using this code in bp-custom.php:

    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
    // for the "age range" search mode
    	if ($f->code == 'field_4' && $f->display == 'range')
    	{
    		$f->display = 'range-select';
    		$range = range (18, 99);
    		$f->options = array ('' => '') + array_combine ($range, $range);
    	}
    
    // for the "range" search mode
    	if ($f->code == 'field_235' && $f->display == 'integer-range')
    	{
    		$f->display = 'range-select';
    		$range = range (0, 100);
    		$f->options = array ('' => '') + array_combine ($range, $range);
    	}
    }
    Thread Starter Carsten Lund

    (@carsten-lund)

    Thanks for the code, it worked with the range, but not the age range.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Could you add

    if ($f->code == 'field_xyz') print_r ($f);

    inside the function? Replace xyz with the ID of the field with the “age range” search mode.

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, thanks for the code, unfortunatlly it adds drop down to all fields, also the distance search fields.

    Regards
    Carsten

    add_action ('bps_field_before_search_form', 'change_display');
    function change_display ($f)
    {
    // for the "age range" search mode
    	if ($f->code == 'field_2389' && $f->display == 'range')
    	if ($f->code == 'field_2389') print_r ($f);
    	{
    		$f->display = 'range-select';
    		$range = range (18, 99);
    		$f->options = array ('' => '') + array_combine ($range, $range);
    	}
    
    // for the "range" search mode
    	if ($f->code == 'field_2038' && $f->display == 'integer-range')
    	{
    		$f->display = 'range-select';
    		$range = range (140, 210);
    		$f->options = array ('' => '') + array_combine ($range, $range);
    	}
    }
    Plugin Author Andrea Tarantini

    (@dontdream)

    Sorry, I forgot to specify that the new line of code should be the first in the function.

    It should display some data useful for debugging.

    Thread Starter Carsten Lund

    (@carsten-lund)

    Hi Andrea, now all search fields are all two drop-down select boxes, but the range display in the edit personal profile section is still two input boxes.

    How do I changes these fields as well, to two drop-down select boxes, to match the search form?

    Thanks

    Best
    Carsten

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Carsten,

    Unfortunately BP Profile Search is unable to customize the Edit Profile page.

    If your field type is provided by a plugin, e.g. BuddyPress Xprofile Custom Field Types, I suggest you ask them for advice.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Range drop-down select code does not apply’ is closed to new replies.