cfs5403 Posted December 14, 2012 Share Posted December 14, 2012 This function will perform get search term from url if 404 not found and redirect the search term to http://www.website.com/?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://www.website.com/?s=[how to put the $search here]', 301 ); } } add_action('template_redirect', 'simple404_redirect'); Quote Link to comment https://forums.phpfreaks.com/topic/271982-help-me-with-this-wordpress-php-function-code/ Share on other sites More sharing options...
trq Posted December 14, 2012 Share Posted December 14, 2012 Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/271982-help-me-with-this-wordpress-php-function-code/#findComment-1399318 Share on other sites More sharing options...
SofWare Posted December 21, 2012 Share Posted December 21, 2012 (edited) Near the bottom is the question :-) It says: wp_redirect( 'http://www.website.com/?s=[how to put the $search here]', 301 ); And for the answer, he should try: wp_redirect( 'http://www.website.com/search/' . $search, 301 ); Edited December 21, 2012 by SofWare Quote Link to comment https://forums.phpfreaks.com/topic/271982-help-me-with-this-wordpress-php-function-code/#findComment-1400786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.