Skip to content

Instantly share code, notes, and snippets.

@atsea
Created November 10, 2014 14:55
Show Gist options
  • Save atsea/3ed90e233e480188ad0b to your computer and use it in GitHub Desktop.
Save atsea/3ed90e233e480188ad0b to your computer and use it in GitHub Desktop.
Build select lists for search form
/**
* How to create an advanced search form for wordpress
* http://fearlessflyer.com/how-to-create-an-advanced-search-form-for-wordpress/
*/
function buildSelect($tax){
$terms = get_terms($tax);
//$tax = preg_replace('/^software_/', '', $tax);
//$tax_name = str_replace('_', ' ', $tax_name);
$prefix = 'software_';
$tax_name = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $tax); //preg_replace('/^software_/', '', $tax);
if (strpos($tax,'categories') !== false) {
$tax_name = substr_replace('Categories', 'Category', $tax);
}
//$tax_name = str_replace('categories', 'category', $tax);
$x = '<div class="group">' . "\n";
$x .= '<fieldset>' . "\n";
$x .= '<legend>' . ucfirst($tax_name) .'</legend>' . "\n";
$x .= '<select id="searchsubmit" class="left" name="'. $tax .'">' . "\n";
$x .= '<option value="">Choose one</option>' . "\n";
foreach ($terms as $term) {
$x .= '<option value="' . $term->slug . '">' . $term->name . ' (' . $term->count .')</option>' . "\n";
}
$x .= '</select>' . "\n";
$x .= '<input class="left icon-search" type="image" src="http://dev-udcp.gotpantheon.com/wp-content/themes/nimble-child/images/search_btn.png">' . "\n";
$x .= '</fieldset></div>';
return $x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment