• Resolved separator

    (@separator)


    hi there Andrea,
    thanks for this awesome plugin!
    i want to make the search field called “City” and that field to be populated based on the users registration respective field named “City” as well.
    so basically i want the dropdown search field to display all the cities from the already registered users who filled that field in the form.
    for example if i have two registered users, one from Toronto and the other one from Montreal, i want both cities to be displayed in the search field automatically as dropdown, after the users filled the “City” field from the registration form.
    is this possible?

    thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi @separator,

    Which type is your “City” registration field (“Text Box”, “Drop Down Select Box”, other)?

    Thread Starter separator

    (@separator)

    hi Andrea,
    thanks for the reply.
    its a Textbox.

    Thread Starter separator

    (@separator)

    hey Andrea, any help on this?
    would be appreciated

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi separator,

    Sorry for the late reply. I think I’m close to a solution, but not there yet.

    I’ll keep you posted!

    Thread Starter separator

    (@separator)

    oh thanks a lot man!
    sorry to bother. will wait…

    Thread Starter separator

    (@separator)

    hi Andrea,
    i found this: https://vikku.info/programming/geodata/geonames-get-country-state-city-hierarchy.htm

    i thought maybe can be helpful?

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi separator,

    I’m going to take a look, thanks, but I hope I can find a simpler solution.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi separator,

    Thank you for your patience!

    I think I found a working solution. Add this code to your bp-custom.php:

    add_action ('bps_field_before_search_form', 'new_display');
    function new_display ($f)
    {
    	global $wpdb;
    	
    	$ID = 27;
    	if ($f->id == $ID)
    	{
    		$query = "SELECT DISTINCT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = $ID";
    		$values = $wpdb->get_col ($query);
    		$f->display = 'selectbox';
    		$f->options = array ();
    		foreach ($values as $value)
    			$f->options[stripslashes ($value)] = stripslashes ($value);
    	}
    }

    Replace 27 with the actual ID of your field, and please let me know how that works for you!

    Thread Starter separator

    (@separator)

    hi man,
    it works great!!! i thank you so much about this.
    even though this is a work around what my client wanted i appreciate this so much!
    also, is there a solution to automatically clear the select box after i click on “search” so there’s no item selected after i go back to the filter page?
    also i dont know how to delete this field https://snag.gy/RFGMxm.jpg because i beleive it gives me an empty item in the dropdown like this: https://snag.gy/SwIVD9.jpg

    however, is it possible to create a filter like the one i posted above? basically thats what my client wants: https://vikku.info/programming/geodata/geonames-get-country-state-city-hierarchy.htm

    i found this great plugin: https://www.ads-software.com/plugins/wp-geonames/ but i need to make it to search for bp profiles when i select the last field (City)

    i’d be happy to pay a reasonable price for a custom work like that.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi separator,

    Glad that my code works for you!

    About your other questions:

    1. Is there a solution to automatically clear the select box after i click on “search” so there’s no item selected after I go back to the filter page?

    Yes, disable Persistent Search in the form edit page.

    2. I don’t know how to delete this field https://snag.gy/RFGMxm.jpg because I believe it gives me an empty item in the dropdown like this: https://snag.gy/SwIVD9.jpg

    You can delete a profile field using the Delete link in the Profile Fields page, but I don’t think it’s causing the blank option in the dropdown. I’ll post a revised code to get rid of that blank option.

    3. Is it possible to create a filter like the one I posted above?

    Yes, I think so. Unfortunately I don’t have much available time at the moment, but you could post your request on jobs.wordpress.net or on a freelancers site.

    Plugin Author Andrea Tarantini

    (@dontdream)

    As promised, this revised code removes the blank dropdown item and sorts the remaining items.

    add_action ('bps_field_before_search_form', 'new_display');
    function new_display ($f)
    {
    	global $wpdb;
    
    	$ID = 27;
    	if ($f->id == $ID)
    	{
    		$query = "SELECT DISTINCT value FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = $ID ORDER BY value";
    		$values = $wpdb->get_col ($query);
    		$f->display = 'selectbox';
    		$f->options = array ();
    		foreach ($values as $value)
    		{
    			$value = trim (stripslashes ($value));
    			if ($value == '')  continue;
    
    			$f->options[$value] = $value;
    		}
    	}
    }

    Remember to replace 27 with the actual ID of your field.

    Thread Starter separator

    (@separator)

    you’re the man!
    thanks a lot!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘auto-populate “City” search field from signup form field’ is closed to new replies.