Title: Location Search
Last modified: August 3, 2017

---

# Location Search

 *  [dabeecher](https://wordpress.org/support/users/dabeecher/)
 * (@dabeecher)
 * [9 years ago](https://wordpress.org/support/topic/location-search-4/)
 * Hello,
 * I have created a custom search form which allows people to search by key word&
   wpbb_job_location
 * If I search a location such as “USA” this works, but if I search anything with
   a space this doesn’t work i.e. New York. Here are the links to the examples
 * [http://www.energizerecruitment.co.uk/jobs/?s=&wpbb_job_location=usa](http://www.energizerecruitment.co.uk/jobs/?s=&wpbb_job_location=usa)
   
   [http://www.energizerecruitment.co.uk/jobs/?s=&wpbb_job_location=new+york](http://www.energizerecruitment.co.uk/jobs/?s=&wpbb_job_location=new+york)
 * Any help would be great.
 * Thanks
 * David

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

 *  Plugin Author [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/)
 * (@wpmarkuk)
 * [9 years ago](https://wordpress.org/support/topic/location-search-4/#post-9377894)
 * Hi David,
 * Pretty sure this is because when using the taxonomy name in the search query 
   string e.g. `wpbb_job_location` WordPress expects to receive a term slug not 
   a term name.
 * For example if you try search for `new-york` you should get the jobs in New York.
   Therefore you could change the input for that field from a `text` input to a `
   select` input and the values of the options would be the term slugs.
 *  [wackyracer8](https://wordpress.org/support/users/wackyracer8/)
 * (@wackyracer8)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/location-search-4/#post-9590543)
 * [@dabeecher](https://wordpress.org/support/users/dabeecher/), did you ever find
   a solution to the search? If so would you please mind sharing?
 * Thanks
 *  Plugin Author [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/)
 * (@wpmarkuk)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/location-search-4/#post-9590862)
 * [@wackyracer8](https://wordpress.org/support/users/wackyracer8/) we offer a search
   plugin for sale which adds search capability to the WP Broadbean plugin.
 * [https://store.highrise.digital/downloads/wp-broadbean-search/](https://store.highrise.digital/downloads/wp-broadbean-search/)
 *  Thread Starter [dabeecher](https://wordpress.org/support/users/dabeecher/)
 * (@dabeecher)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/location-search-4/#post-9637393)
 * [@wackyracer8](https://wordpress.org/support/users/wackyracer8/) I just hooked
   upto the search query and amended it so I could do it with the full name…
 * I’ve added my code below which worked for me
 *     ```
       function advanced_search_query($query) {
   
       	if($query->is_search()) {
   
       		if (!empty($_GET['search_location'])):
       			$slug = str_replace(" ", "-", $_GET['search_location']);
       			$tax_query = array(
       				 array(
       				    'taxonomy'=>'wpbb_job_location',
       				    'field'=> 'slug' ,
       				    'terms'=>  $slug,
       				 ),
       			);
   
       			$query->set('tax_query',$tax_query);
       		endif;
   
       		return $query;
       	}
       }
   
       add_action('pre_get_posts', 'advanced_search_query', 1000);
       ```
   
 *  Plugin Author [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/)
 * (@wpmarkuk)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/location-search-4/#post-9638446)
 * Just a quick tip – you should never be using `$_GET` parameters raw. They should
   always be checked first using the WordPress sanitization function. Therefore 
   replace:
 * `$slug = str_replace(" ", "-", $_GET['search_location'] );`
 * With this:
 * `$slug = str_replace(" ", "-", sanitize_text_field( $_GET['search_location'] ));`
    -  This reply was modified 8 years, 9 months ago by [Mark Wilkinson](https://wordpress.org/support/users/wpmarkuk/).
 *  [wackyracer8](https://wordpress.org/support/users/wackyracer8/)
 * (@wackyracer8)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/location-search-4/#post-9654357)
 * [@dabeecher](https://wordpress.org/support/users/dabeecher/) Cheers, that has
   worked a treat. Top man.

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

The topic ‘Location Search’ is closed to new replies.

 * ![](https://ps.w.org/wpbroadbean/assets/icon-256x256.png?rev=2046685)
 * [WP Broadbean](https://wordpress.org/plugins/wpbroadbean/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpbroadbean/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpbroadbean/)
 * [Active Topics](https://wordpress.org/support/plugin/wpbroadbean/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpbroadbean/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpbroadbean/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [wackyracer8](https://wordpress.org/support/users/wackyracer8/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/location-search-4/#post-9654357)
 * Status: not resolved