Support » Plugin: GEO my Wordpress » Only show results for certain state?

  • Resolved wzshop


    I want to only show the results for a certain state (or country). Now I know I can filter those when creating a form, but is it also possible to filter this dynamically using a filter/action function in functions.php?

    Thus I guess my question is; how can I alter the query that gets the different locations?, using a function?

    Thanks a million!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eyal Fitoussi


    Hello @wzshop,

    You can use the function below to filter the page load results based on a specific state and/or country ( country filter is marked out ):

    function gmw_cusotm_filter_address_fields( $gmw ) {
    	// To limit the functon to a specific form, change 1 to the ID of your GEO my WP's form.
    	if ( 1 !== absint( $gmw['ID'] ) ) {
    		return $gmw;
    	// Filter by state.
    	$gmw['page_load_results']['state_filter'] = 'Florida';
            // Filter by country.
            //$gmw['page_load_results']['country_filter'] = 'United States';
    	return $gmw;
    add_filter( 'gmw_default_form_values', 'gmw_cusotm_filter_address_fields', 50 );

    Note that the filter above ( ‘gmw_default_form_values’ ) executes before any queries take place and allow you to modify the form object ( which is an array ). So you can use that filter to modify the different address filters of the form.

    So the filter doesn’t really modify the search query. If for some reason you do need to modify the search query I will need to look up a different filter for you.

    I hope this helps.

    Thread Starter wzshop


    Thank you so much @ninjew! That helped me a lot:)

    • This reply was modified 11 months ago by wzshop.
    Plugin Author Eyal Fitoussi


    You are welcome, @wzshop. I am glad I could help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Only show results for certain state?’ is closed to new replies.