Advertisement
Guest User

Untitled

a guest
Oct 11th, 2012
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. function wpse66815_search_query_string( $wp_query ) {
  2.     if (!is_admin() && is_search()) {
  3.  
  4.         //print_r($search);
  5.  
  6.         global $wp_query,$wpdb;
  7.  
  8.         // get search term
  9.         $search_term = $wp_query->query_vars['s'];
  10.  
  11.         //print_r($search_term);
  12.  
  13.         // specify string we'll use to replace
  14.         $replace_var = 'TL';
  15.  
  16.         // find matches for that string
  17.         preg_match_all("/{$replace_var}(?:[^0-9]*)(\d+)/i", $search_term, $out);
  18.  
  19.         // if there's no matches, return the normal search
  20.         if ( empty($out[0]) )
  21.             return $wp_query;
  22.  
  23.         // find/generate the search term with the replacement
  24.         $modified_search_term = preg_replace(
  25.              "/{$replace_var}(?:[^0-9]*)(\d+)/i"
  26.             ,"{$replace_var}-$1"
  27.             ,$search_term
  28.         );
  29.  
  30.  
  31.         // combine both the regular and modified search term
  32.         $new_search[] = $search_term;
  33.         $new_search[] = $modified_search_term;
  34.  
  35.         //print_r($new_search);
  36.  
  37.         // set $search equal to results
  38.         $wp_query->query_vars['s'] = implode(' ',$new_search);
  39.  
  40.         //print_r($search);*/
  41.     }
  42.     return $wp_query;
  43. }
  44. add_filter('relevanssi_modify_wp_query', 'wpse66815_search_query_string');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement