Created
November 10, 2014 14:55
-
-
Save atsea/3ed90e233e480188ad0b to your computer and use it in GitHub Desktop.
Build select lists for search form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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