Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpse66815_search_query_string( $wp_query )
- {
- if (!is_admin() && is_search()) {
- //print_r($search);
- global $wp_query,$wpdb;
- // get search term
- $search_term = $wp_query->query_vars['s'];
- //print_r($search_term);
- // specify string we'll use to replace
- $replace_var = 'TL';
- // find matches for that string
- preg_match_all("/{$replace_var}(?:[^0-9]*)(\d+)/i", $search_term, $out);
- // if there's no matches, return the normal search
- if ( empty($out[0]) )
- return $wp_query;
- // find/generate the search term with the replacement
- $modified_search_term = preg_replace(
- "/{$replace_var}(?:[^0-9]*)(\d+)/i"
- ,"{$replace_var}-$1"
- ,$search_term
- );
- // combine both the regular and modified search term
- $new_search[] = $search_term;
- $new_search[] = $modified_search_term;
- print_r($new_search);
- // generate the new search query
- $new_string_parts[] = $wpdb->prepare(
- "
- AND ((({$wpdb->posts}.post_title LIKE '%%%s%%')
- OR ({$wpdb->posts}.post_content LIKE '%%%s%%'))
- "
- ,like_escape( $new_search[0] )
- ,like_escape( $new_search[0] )
- );
- $new_string_parts[] = $wpdb->prepare(
- "
- OR (({$wpdb->posts}.post_title LIKE '%%%s%%')
- OR ({$wpdb->posts}.post_content LIKE '%%%s%%')))
- "
- ,like_escape( $new_search[1] )
- ,like_escape( $new_search[1] )
- );
- foreach ( $new_search as $keyword)
- {
- if ($keyword === reset($new_search)) {
- $new_string_parts[] = $wpdb->prepare(
- "
- AND ((({$wpdb->posts}.post_title LIKE '%%%s%%')
- OR ({$wpdb->posts}.post_content LIKE '%%%s%%'))
- "
- ,like_escape( $keyword )
- ,like_escape( $keyword )
- );
- }
- elseif ($keyword === end($new_search)) {
- $new_string_parts[] = $wpdb->prepare(
- "
- OR (({$wpdb->posts}.post_title LIKE '%%%s%%')
- OR ({$wpdb->posts}.post_content LIKE '%%%s%%')))
- "
- ,like_escape( $keyword )
- ,like_escape( $keyword )
- );
- }
- else {
- $new_string_parts[] = $wpdb->prepare(
- "
- OR (({$wpdb->posts}.post_title LIKE '%%%s%%')
- OR ({$wpdb->posts}.post_content LIKE '%%%s%%'))
- "
- ,like_escape( $keyword )
- ,like_escape( $keyword )
- );
- }
- }
- // set $search equal to results
- $search = implode( " ", $new_string_parts );
- //print_r($search);*/
- }
- return $wp_query;
- }
- add_filter('relevanssi_modify_wp_query', 'wpse66815_search_query_string');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement