Title: 404 Search Function for WordPress
Last modified: August 18, 2016

---

# 404 Search Function for WordPress

 *  [Laughinglizard](https://wordpress.org/support/users/laughinglizard/)
 * (@laughinglizard)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/)
 * This is a modification of the 404 function found at [NSLog](http://nslog.com/archives/2003/02/26/404_search_function_code.php).
   This is tweaked such that if a page is not found on your WordPress blog, the 
   part of the URI beyond the domain name is stripped off and fed into the WordPress
   search function. If only one post if found, that post is directly loaded. Otherwise
   the whole list of posts is loaded and displayed.
    Learn more about it here: [http://weblogtoolscollection.com/archives/2004/08/05/404-search-function-for-wordpress/](http://weblogtoolscollection.com/archives/2004/08/05/404-search-function-for-wordpress/)

Viewing 5 replies - 16 through 20 (of 20 total)

[←](https://wordpress.org/support/topic/404-search-function-for-wordpress/?output_format=md)
[1](https://wordpress.org/support/topic/404-search-function-for-wordpress/?output_format=md)
2

 *  Anonymous
 * [21 years, 10 months ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-79920)
 * i m getting this error:
    `Parse error: parse error, unexpected ';' in /home/httpd/
   vhosts/deydas.com/httpdocs/404.php on line 131` –[abhi](http://www.deydas.com).
 *  [davidprince](https://wordpress.org/support/users/davidprince/)
 * (@davidprince)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-79923)
 * Did you take the code directly from the authors site? If so it has been styled
   and you need to use unstyled text. Ie the curly quotes are not acceptable. Try
   copying the code directly from this post.
    `<? $search_term = substr($_SERVER['
   REQUEST_URI'],1); $search_term = urldecode(stripslashes($search_term)); $search_url
   = 'http://davidblog.ws/blog/index.php?s='; $full_search_url = $search_url . $
   search_term; $full_search_url = preg_replace('/ /', '%20', $full_search_url);
   $full_page = implode("", file($full_search_url)); print_r($full_page); die();?
   >
 *  Anonymous
 * [21 years, 10 months ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-79924)
 * yes david, i’ve unstyled it but still nothing…
    –[abhi](http://www.deydas.com).
 *  [Ruby Sinreich](https://wordpress.org/support/users/rubyji/)
 * (@rubyji)
 * [21 years, 10 months ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-79925)
 * FYI, in case anyone cares, I fixed my directory problem and made one more improvement.
   Now it only makes the new search term if it’s a 404 error (this page handles 
   all errors). So in my conditional cases that evaluate `getenv("REDIRECT_STATUS")`
   I added this code to part for 404’s:
    `$search_term = substr($_SERVER['REQUEST_URI'],
   1); $find = array ("'.html'", "'.+/'", "'[-/_]'") ; $replace = " " ; $new_search
   = preg_replace ( $find , $replace , $search_term ); and then in the search field
   I just put <?php echo ($new_search); ?> which only has a value if it was a 404
   error.
 *  [sva](https://wordpress.org/support/users/sva/)
 * (@sva)
 * [21 years, 1 month ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-80064)
 * Im loving the hack, but i’ve noticed a lot of searches for “/archives/2004/12/
   27/post-name/”, which when searched for doesn’t bring up any posts, how would
   i only have it search for “/post-name/”?

Viewing 5 replies - 16 through 20 (of 20 total)

[←](https://wordpress.org/support/topic/404-search-function-for-wordpress/?output_format=md)
[1](https://wordpress.org/support/topic/404-search-function-for-wordpress/?output_format=md)
2

The topic ‘404 Search Function for WordPress’ is closed to new replies.

 * 20 replies
 * 8 participants
 * Last reply from: [sva](https://wordpress.org/support/users/sva/)
 * Last activity: [21 years, 1 month ago](https://wordpress.org/support/topic/404-search-function-for-wordpress/page/2/#post-80064)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
