Last active
August 29, 2015 14:18
-
-
Save Fitoussi/8c0ac31c70518186fef3 to your computer and use it in GitHub Desktop.
GMW - Filter Results by State part 4
This file contains 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
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> | |
<?php | |
} | |
add_action( 'gmw_search_form_before_distance', 'gmw_states_dropdown', 15 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment