• I have default values using Xprofile fields, which auto populate with the default values, Is there anyway that the plugin can also automatically select a default option, rather than user having to select an option?

    For example I have a website that is based in India with 90% users are Indian.
    I have India selected as the default country for the Xprofile field.
    Can BP profile search automatically populate India in the country field?

Viewing 15 replies - 1 through 15 (of 17 total)
  • Or if I have a search form with shortcode ..ie [bps_form id=44]

    Is there a way for it to display results for the country as India, with field hidden in search bar?

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi wpress2021,

    To assign a default value to your search fields, you can use the code explained in:

    https://dontdream.it/bp-profile-search-5-3/

    And to make a directory of users from India, you can use the [bps_directory] shortcode with ‘hidden filters’, see:

    https://dontdream.it/bp-profile-search-4-8/

    Then you can use that directory as the ‘target directory’ of your search form.

    Please let me know if that works for you!

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    So acording to your code, I would type the following if my field is ‘Country’ abd default value is ‘India”

    add_action (‘bps_field_before_search_form’, ‘set_default’);
    function set_default ($f)
    {
    if ($f->code == ‘field_Ciuntry’) // replace 34 with your field ID
    {
    // assign the default value
    $f->value = India;
    }
    }

    Sorry not advanced user so just trying to make sure!

    Also, I tried above using Snippet plugin and it didn’t work. Although I cannot find the bp-custom.php file in my plugins folder. Just to note, I am using Buddyboss.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi again,

    First, you need to determine your field ID. Go to BuddyBoss => Profiles and Edit your profile field. Now look at your browser address bar, it should display something like:

    https://example.com/wp-admin/admin.php?page=bp-profile-setup&mode=edit_field&group_id=1&field_id=362

    Your field ID is the last number, in the above example it’s 362.

    So your code will be:

    add_action ('bps_field_before_search_form', 'set_default');
    function set_default ($f)
    {
    	if ($f->code == 'field_362')    // replace 362 with your field ID
    	{
    		// assign the default value
    		$f->value = 'India';
    	}
    }

    If you can’t find bp-custom.php in your plugin directory, just go ahead and create it, then put this in its first line:

    <?php
    

    Now you can add your code, explained above.

    Does that work for you?

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    Thanks, totally works now! Appreciate your help!

    I was wondering if there is a solution for the following?

    I have a gender field and I need the default value in the search bar to be the same as the users gender Us this possible?

    r123ze

    (@r123ze)

    @dontdream andrea do you know how to remove contains text in field label, for example i have input.

    City contains
    <input …. :>

    I want to remove contains or hide it in front of the city field label….

    if I choose also “match any” mode, it will display it in front of field label.. i want to remove this, any hook or function to do it?

    thanks

    • This reply was modified 4 years ago by r123ze.
    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi wpress2021,

    You can expand your previous code as follows:

    add_action ('bps_field_before_search_form', 'set_default');
    function set_default ($f)
    {
    	if ($f->code == 'field_362')    // replace 362 with your field ID
    	{
    		// assign the default value
    		$f->value = 'India';
    	}
    	else if ($f->code == 'field_27')    // replace 27 with your Gender field ID
    	{
    		$user_id = bp_loggedin_user_id ();
    		if ($user_id != 0)
    		{
    			$gender = xprofile_get_field_data (27, $user_id);   // replace 27
    			$f->value = $gender;
    		}
    	}
    }

    And thanks for your review!

    Plugin Author Andrea Tarantini

    (@dontdream)

    To r123ze:

    You can select Customize => Additional CSS, and enter this code:

    .bps-form label span {display: none;}

    r123ze

    (@r123ze)

    thanks so much, btw i use youzer plugin, and bp search profile displayed above default filter of youzer, but i want to change it place to place along with the default filter of youzer, is that possible to change place where the bps should be displayed?

    Thanks so much, and great plugin..

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    Thanks Andrea

    I Tried this a few times and get the following error.

    https://ibb.co/PD829L2

    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 2:

    syntax error, unexpected ‘&’
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

    I did the following:

    add_action ('bps_field_before_search_form', 'set_default');
    function set_default ($f)
    {
    if ($f->code == 'field_224') // 224 field no. for country
    {
    // assign the default value
    $f->value = 'India';
    }
    else if ($f->code == 'field_2') // 2 field no.for gender
    {
    $user_id = bp_loggedin_user_id ();
    if ($user_id != 0)
    {
    $gender = xprofile_get_field_data (2, $user_id); // 2 fieldID for gender
    $f->value = $gender;
    }
    }
    }

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    Sorry, Please ignore last code,I tried this code and got the error given before.

    add_action ('bps_field_before_search_form', 'set_default');
    function set_default ($f)
    {
    if ($f->code == 'field_224') // 224 field ID for country
    {
    // assign the default value
    $f->value = 'India';
    }
    else if ($f->code == 'field_2') // 2 field ID for gender
    {
    $user_id = bp_loggedin_user_id ();
    if ($user_id != 0)
    {
    $gender = xprofile_get_field_data (2, $user_id); // field ID for gender 2
    $f->value = $gender;
    }
    }
    }

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    I got this error from the code:

    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 1:

    syntax error, unexpected ‘&’
    The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    Sorry Andrea,got it working now on the first code!

    Thanks for your help! Awesome plugin!

    Thread Starter dfgergrfdegfdg fdgdfgdfgdfgfd

    (@wpress2021)

    Andrea, the code you gave me works,but I realized I asked for the wrong thing.

    I have 2 fields, ‘Gender’ field ID 2 and ‘Searching for’ field ID 2552.

    I need the users gender to automatically populate in the searching for field instead of gender.

    This code perfectly brings up the gender in gender field, so I am guessing there is a way to use this to achieve it?

    add_action (‘bps_field_before_search_form’, ‘set_default’);
    function set_default ($f)
    {
    if ($f->code == ‘field_224’) // 224 field no. for country
    {
    // assign the default value
    $f->value = ‘India’;
    }
    else if ($f->code == ‘field_2’) // 2 field no.for gender
    {
    $user_id = bp_loggedin_user_id ();
    if ($user_id != 0)
    {
    $gender = xprofile_get_field_data (2, $user_id); // 2 fieldID for gender
    $f->value = $gender;
    }
    }
    }

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi wpress2021,

    You can try this:

    add_action ('bps_field_before_search_form', 'set_default');
    function set_default ($f)
    {
    	if ($f->code == 'field_224') // 224: country
    	{
    		// assign the default value
    		$f->value = 'India';
    	}
    	else if ($f->code == 'field_2552') // 2552: searching for
    	{
    		$user_id = bp_loggedin_user_id ();
    		if ($user_id != 0)
    		{
    			$gender = xprofile_get_field_data (2, $user_id); // 2: gender
    			$f->value = $gender;
    		}
    	}
    }

    The only change is in the ‘else if’ line.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Default Value in Search Forms’ is closed to new replies.