• Resolved nibblers

    (@nibblers)


    Hi! Great plugin.

    I’m wondering if there is a solution for this need:

    In my membership directories, there are a couple of custom search fields that are numerical. For example one is “Region”. These regions are defined in the database as numbers, but on the front end we’d like to allow searching by their common names eg. “South”, “North”. Obviously the region number equals a common name: 1 = South.

    Currently, when the user searches, they have to search using a number. We could always offer them a “key” printed on the page to elaborate what number equals what region, but the search will return region 10 when 1 is input in the search box (which is of course expected behavior on these particular search fields).

    Ideally, I’d like to do these things in order of preference:

    1.) Instead of typed search, is there anyway to present a drop down of the common names to search from? A drop down that presented North, South etc. This would in turn search the appropriate number?

    2.) If that’s not possible, can the search be performed as an exact match? So if someone searched Region “1” it would ONLY return region 1 and not also region 10?

    I’m open to using search filters as well as other plugins. Any advice appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • SuitePlugins

    (@suiteplugins)

    Hi @nibblers,

    You can use the script below to get the first solution done. All you have to is change the meta_key to the meta key for regions and update the choices to some thing like

    1;North
    2;South

    The solution should work but there would be a bit more of code needed to get the region on the profile page to display North instead of 1. I can put together a blog post or gist on how to get this more universal so you don’t have to set a manual each time you need to do some thing like this.

    
    function example_um_select_dropdown_dynamic_options_callback( $options, $data = array() ) {
    	$region_meta_key = 'region_select_1';
    	if ( $region_meta_key != $data['metakey'] ) {
    		return $options;
    	}
    	if ( ! empty( $options ) ) {
    		$new_options = array();
    		foreach( $options as $option ) {
    			list ($k,$v) = explode( ';', $option );
    			$new_options[$k] = $v;
    		}
    		$options = $new_options;
    	}
    	return $options;
    }
    add_filter( 'um_select_dropdown_dynamic_options', 'example_um_select_dropdown_dynamic_options_callback', 12, 2 );
    
    function example_um_select_options_pair_callback( $result = '', $data = array() ) {
    	$region_meta_key = 'region_select_1';
    	if ( $region_meta_key == $data['metakey'] ) {
    		return true;
    	}
    	return $result;
    }
    add_filter( 'um_select_options_pair', 'example_um_select_options_pair_callback', 12, 2 );
    
    Thread Starter nibblers

    (@nibblers)

    Many thanks for taking the time, friend.

    I’m a bit confused. Currently, I cannot even define how to present a drop down in the search options! I implement search, and select the fields I want to include and they are all listed as simple text boxes. Can you elaborate?

    THANK YOU

    Thread Starter nibblers

    (@nibblers)

    Any extra tips here? Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Customize Membership Directory Search’ is closed to new replies.