Title: Help me with this wordpress php function code
Last modified: August 20, 2016

---

# Help me with this wordpress php function code

 *  [cfs5403](https://wordpress.org/support/users/cfs5403/)
 * (@cfs5403)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/help-me-with-this-wordpress-php-function-code/)
 * This function will perform get search term from url if 404 not found and redirect
   the search term to [http://localhost/wordpress/?s=](http://localhost/wordpress/?s=)(
   my search term here), can help me edit the code abit?
 * function simple404_redirect() {
    if(is_404()) {
 * $get_params = “”;
    if ( preg_match(“@/?(\?.*)@”, $_SERVER[“REQUEST_URI”], $matches)){
   $get_params = $matches[1]; }
 * // Extract search term from URL
    $patterns_array = array(); if ( ( $patterns 
   = trim( get_option(‘ignored_patterns’ ) ) ) ) { $patterns_array = explode( ‘\
   n’, $patterns ); }
 * $patterns_array[] = “/(trackback|feed|(comment-)?page-?[0-9]…
    $patterns_array[]
   = “\.(html|php)$”; $patterns_array[] = “/?\?.*”; $patterns_array = array_map(
   create_function(‘$a’, ‘$sep = (strpos($a, “@”) === false ? “@” : “%”); return
   $sep.trim($a).$sep.”i”;’), $patterns_array);
 * $search = preg_replace( $patterns_array, “”, urldecode( $_SERVER[“REQUEST_URI”]));
   
   $search = basename(trim($search)); $search = str_replace(“_”, “-“, $search); 
   $search = trim(preg_replace( $patterns_array, “”, $search)); $search_words = 
   trim(preg_replace( “@[_-]@”, ” “, $search));
 * wp_redirect( ‘[http://localhost/wordpress/?s=%5Bhow](http://localhost/wordpress/?s=%5Bhow)
   do I put my search term here?] ‘, 301 );
    } } add_action(‘template_redirect’,‘
   simple404_redirect’);

The topic ‘Help me with this wordpress php function code’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [cfs5403](https://wordpress.org/support/users/cfs5403/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/help-me-with-this-wordpress-php-function-code/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
