Title: Escape search
Last modified: May 29, 2018

---

# Escape search

 *  [schubling](https://wordpress.org/support/users/schubling/)
 * (@schubling)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/escape-search/)
 * Hello,
 * Thanks for your plugin ! I had some problems to match keywords with special characters
   like [ ] so I made a small modification => I’ve escaped the “keyword” before 
   the preg_match test (line 264 of class-search-keyword-redirect.php) :
    `$keyword
   = preg_quote($keyword);`
 * Hope you could add this to your code 🙂
 * Cheers,
    Diego

Viewing 1 replies (of 1 total)

 *  Thread Starter [schubling](https://wordpress.org/support/users/schubling/)
 * (@schubling)
 * [8 years ago](https://wordpress.org/support/topic/escape-search/#post-10462918)
 * Rectification.. you could replace the “loop through each keyword” by checking
   directly if the search query is a key of the redirection array.
 * This is the updated function “search_keyword_redirect” :
 *     ```
       	/**
       	 * Attempt to match keywords to search query and redirect on match
       	 *
       	 * @since    0.1.0
       	 */
       	public function search_keyword_redirect() {
   
       		if ( ! is_search() ) {
       			return;
       		} // not a search
   
       		// get options
       		$redirects = get_option( 'ww_keyword_redirects' );
   
       		// check if options exist
       		if ( ! empty( $redirects ) ) {
   
       			if (array_key_exists(get_search_query(), $redirects)){
       				// redirect to url
       				wp_redirect( $redirects[get_search_query()][0] );
       				exit();
       			}
   
       			// no keywords matched
       			unset( $redirects );
   
       			return;
   
       		} else {
   
       			return; // no redirects
   
       		}
   
       	} // END search_keyword_redirect()
       ```
   
 * Regards,
    Diego

Viewing 1 replies (of 1 total)

The topic ‘Escape search’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-search-keyword-redirect_7accc8.
   svg)
 * [Search Keyword Redirect](https://wordpress.org/plugins/wp-search-keyword-redirect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-search-keyword-redirect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-search-keyword-redirect/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-search-keyword-redirect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-search-keyword-redirect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-search-keyword-redirect/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [schubling](https://wordpress.org/support/users/schubling/)
 * Last activity: [8 years ago](https://wordpress.org/support/topic/escape-search/#post-10462918)
 * Status: not resolved