Created
August 21, 2019 18:36
-
-
Save chriswagoner/1440191fefbb9e7ce9ab92f2a09123f2 to your computer and use it in GitHub Desktop.
Toolset - Dynamically populate the dropdown to select the user's current location
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
| // Add this to the Search and Pagination JS field. | |
| // This will populate the dropdown (view filter) to set the state that the user is currently in. You can target any filter you have on the page. | |
| // You will need to install the plugin CF Geo Plugin. They have shortcode and you can utilize JS for location attributes. | |
| // Here we're changing a State dropdown for locations. Change to fit your project. | |
| jQuery(document).ready(function () { | |
| if(jQuery("body:not(.home) #wpv_control_select_wpcf-org-state option[selected='selected']").val() === "") { | |
| var state = window.cfgeo.region; | |
| var stateHandle = '#wpv_control_select_wpcf-org-state option[value="' + state + '"]'; | |
| jQuery(stateHandle).attr('selected', true).trigger('change'); | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment