Skip to content

Instantly share code, notes, and snippets.

@curtismchale
Created September 5, 2011 22:04
Show Gist options
  • Save curtismchale/1196027 to your computer and use it in GitHub Desktop.
Save curtismchale/1196027 to your computer and use it in GitHub Desktop.
gives the user more options to filter the site by (like meta values)
<form method="get" id="searchform" action="<?php echo home_url(); ?>/">
<label class="hidden" for="s"><?php _e('', 'comienzo'); ?></label>
<input type="search" class="text" value="search site" name="s" id="s" />
<select name="sport">
<option value="" />Choose sport</option>
<?php
$metakey = 'sfn_tan_choose_sport';
$sports = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($sports) {
foreach ($sports as $sport) {
echo "<option value=\"" . $sport . "\">" . $sport . "</option>";
}
}
?>
</select>
<select name="fbposition">
<option value="" />Choose football position</option>
<?php
$metakey = 'sfn_tan_football_position';
$items = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($items) {
foreach ($items as $item) {
echo "<option value=\"" . $item . "\">" . $item . "</option>";
}
}
?>
</select>
<select name="state">
<option value="" />Choose state</option>
<?php
$metakey = 'state';
$items = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->usermeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($items) {
foreach ($items as $item) {
echo "<option value=\"" . $item . "\">" . $item . "</option>";
}
}
?>
</select>
<select name="grad">
<option value="" />Choose graduation year</option>
<?php
$metakey = 'sfn_tan_hs_graduation_year';
$items = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($items) {
foreach ($items as $item) {
echo "<option value=\"" . $item . "\">" . $item . "</option>";
}
}
?>
</select>
<input type="hidden" name="post_type" value="athlete_profile" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment