Mod for adding drop down for cities search function
Hi,
I think a lot of people have asked about this feature. Now I am not a wordpress developer or classipress expert and this actually is my first experience with
WP/CP but it turns out adding the extra search function is not that hard.
Add a drop down box in header.php wherever you like it:
<div class="recordfromblog">
<form action="http://localhost:80/wordpress/" method="get" id="searchform" class="form_search">
<input name="s" type="text" id="s" value="What are you looking for?" onfocus="if (this.value == 'What are you looking for?') {this.value = '';}" onblur="if (this.value == '') {this.value = '';}" class="editbox_search" />
<select name='cat' id='cat' class='postform' >
<option value='0' selected='selected'>All Categories</option>
<option class="level-0" value="1">Uncategorized</option>
<option class="level-0" value="4">Cars</option>
<option class="level-1" value="5">4×4</option>
<option class="level-0" value="6">Jobs</option>
<option class="level-0" value="8">Clasiffieds</option>
<option class="level-1" value="9">TV</option>
</select>
<select name='where' id='where' class='postform' >
<option value='' selected='selected'>All Cities</option>
<option class="level-0" value="Amsterdam">Amsterdam</option>
<option class="level-0" value="New York">New York</option>
<option class="level-0" value="Dubai">Dubai</option>
</select>
<input type="submit" class="btn_orange" value="Search" title="Search" id="go" name="sa" />
</form>
</div>
The way Classipress performs a query is quite ingenious and it will automatically include custom fields. But some people, like me, still would like to offer the end user more options for searching. Like this drop down.
Classipress basically has one GET variable S which will hold the whole query. After we added the above drop down the new query will look like this:
?s=Porsche&cat=0&where=New%20York&sa=Search
The trick is to combine the two search terms, Porsche and New York, into one query that CP will use to search the records.
In theme-functions.php find the line that starts with:
$query = '';
$var_q = stripslashes($_GET['s']);
and change it to:
$query = '';
$var_q = stripslashes($_GET['s']) . '+' . stripslashes($_GET['where']);
This mod will basically combine the two separate search terms back into one after which CP will use the single query as if you had typed Porsche New York into the search box.
For now I have not found any issues with this mod but let me know about any issues.
Gr