Enter your form where ever you plan to display it
/**** The Form ****/
<form name="searchcars" method="get" action="http://yourdomain.com/your-page-template-slug">
<label>Search</label>
<input type="text" name="searchfor">
<label>Location</label>
<Select name="location">
<?php
$locations = get_terms('locations');
foreach($locations as $location)
{
?>
<option value="<?php echo $location->slug; ?>"><?php echo $location->name; ?></option>
<?php
}
?>
</select>
<button type="select" name="search">Search</button>
</form>
Create a new file template, and assign it to a page the slug from this is used as the action for your above form.
<?php
/*
*Template Name: Custom Search
*/
$searchterm = isset($_GET['searchfor']) ? $_GET['searchfor'] : '';
$location = isset($_GET['location']) ? $_GET['location'] : '';
$query = new WP_Query(array(
'post_type' => '...', /** Replace ... with the name of your custom post type **/
'location' => $location, /** Replace the 'location' with '<name-of-your-taxonomy>' **/
'posts_per_page' => 10,
'like' => $searchterm /** This is what we have added with the custom filter **/
)) ;
while($query->have_posts()) : $query->the_post();
/*output the results **/
endwhile;
?>
Enter This into your functions file to add the like paramater to wordpress queries, as an array option.
<?php
/** Like Filter ***/
add_filter( 'posts_where', 'wpse18703_posts_where', 10, 2 );
function wpse18703_posts_where( $where, &$wp_query )
{
global $wpdb;
if ( $wpse18703_title = $wp_query->get( 'like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $wpse18703_title ) ) . '%\'';
}
return $where;
}
?>
Note Reference :
WP_Query with “post_title LIKE ‘something%'”?