Skip to content

Instantly share code, notes, and snippets.

@Fitoussi
Last active August 29, 2015 14:18
Show Gist options
  • Save Fitoussi/2bcaf119a0ed8b0f03f7 to your computer and use it in GitHub Desktop.
Save Fitoussi/2bcaf119a0ed8b0f03f7 to your computer and use it in GitHub Desktop.
GMW - Filter Results by State part 1
function gmw_states_dropdown( $gmw ) {
global $wpdb;
//get states exist in locations table in database
//Note that DISTINCT is being used to make sure each state called only once.
$states = $wpdb->get_col("
SELECT DISTINCT `state_long`
FROM {$wpdb->prefix}places_locator
WHERE `state_long` IS NOT NULL
and trim(coalesce(state_long, '')) <>''
ORDER BY `state_long`");
?>
<!--- create the states select box.
note that the javascript that automatically
submits the form when state value changes -->
<select class="gmw-state-dropdown" name="gmw_state"
onchange="jQuery(this).closest('form').submit()">
<option value="" selected="selected">State</option>
<!--- loop through states and add to the select box -->
<?php foreach ( $states as $state ) { ?>
<option value="<?php echo $state; ?>">
<?php echo $state; ?>
</option>
<?php } ?>
</select>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment