Title: Some code pointers needed
Last modified: August 19, 2016

---

# Some code pointers needed

 *  [austerus](https://wordpress.org/support/users/austerus/)
 * (@austerus)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/some-code-pointers-needed/)
 * Greetings,
 * Recently I’ve started playing around with my wp installation and I’ve come across
   a need to force some extra cleanup of the variable that’s used to searching posts(
   that $_GET[“s”] sent by the search form.
 * Now I came across the get_search_query function which returns the value of that
   GET key for use, but apparently it’s used only to repopulate the search input
   because the search results of the original variable are still displayed (although
   my modified value does appear in the box).
 * Can someone point me to the place where the value which is actually used in the
   SQL query appears?
 * Thanks

Viewing 1 replies (of 1 total)

 *  [sojweb](https://wordpress.org/support/users/sojweb/)
 * (@sojweb)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/some-code-pointers-needed/#post-1033200)
 * It’s in `wp-includes/query.php` on lines 1739-1762:
 *     ```
       // If a search pattern is specified, load the posts that match
       if ( !empty($q['s']) ) {
       	// added slashes screw with quote grouping when done early, so done later
       	$q['s'] = stripslashes($q['s']);
       	if ( !empty($q['sentence']) ) {
       		$q['search_terms'] = array($q['s']);
       	} else {
       		preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q['s'], $matches);
       		$q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
       	}
       	$n = !empty($q['exact']) ? '' : '%';
       	$searchand = '';
       	foreach( (array) $q['search_terms'] as $term) {
       		$term = addslashes_gpc($term);
       		$search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
       		$searchand = ' AND ';
       	}
       	$term = $wpdb->escape($q['s']);
       	if (empty($q['sentence']) && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )
       		$search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}')";
   
       	if ( !empty($search) )
       		$search = " AND ({$search}) ";
       }
       ```
   
 * I think, though, you’d be better off using a filter or something.

Viewing 1 replies (of 1 total)

The topic ‘Some code pointers needed’ is closed to new replies.

## Tags

 * [get](https://wordpress.org/support/topic-tag/get/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * 1 reply
 * 2 participants
 * Last reply from: [sojweb](https://wordpress.org/support/users/sojweb/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/some-code-pointers-needed/#post-1033200)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
