Support » Plugin: GEO my WordPress » Possible to set the default 'starting address' on the fly?

  • Resolved PinkishHue

    (@pinkishhue)



    Any idea how I could set the ‘starting address’ (that we can input when setting up a form) on the fly? Possibly using the post title (the_title) (or any piece of post meta data if not title).

    I would like (for example) a list of posts with locations within 20 miles to be automatically listed on page load, which can be done using the default ‘starting address’.

    Thanks for any advice anyone can give.

    https://wordpress.org/plugins/geo-my-wp/

Viewing 3 replies - 1 through 3 (of 3 total)
  • I wonder if this post on geomywp.com can help?:

    https://geomywp.com/support/forums/topic/shortcode-to-display-search-results-on-pages/

    I have tried editing the code to suit my needs but I am missing something (or a lot of things!)

    (I’ve been testing this by adding a post code by hand (replaced with *MYDATA* below for privacy) )

    I’ve tested both:

    $gmw->form[‘search_form’][‘address_filter’][‘title’]

    and

    $gmw->form[‘page_load_results’][‘address_filter’]

    so have left both in the code below:

    function gmw_formload( $gmw ) {
    
    if ( isset( $gmw->form['in_widget'] ) )
    return;
    
    $mypostcode = "*MYDATA*";
    //will control only form with ID 1
    if ( $gmw->form['ID'] == 1 ) {
    //set post type
    $gmw->form['search_form']['post_types'] = array('post');
    $gmw->form['search_form']['address_filter']['title'] = $mypostcode;
    $gmw->form['page_load_results']['address_filter'] = $mypostcode;
    }
    }
    add_filter( 'gmw_main_shortcode_custom_function',  'gmw_formload', 99 );
    Plugin Author Eyal Fitoussi

    (@ninjew)

    Hello PinkishHue,
    You were in the right direction but you were not using the correct hook. Try the script below ( in the functions.php of your theme ):

    function gmw_formload( $gmw ) {
    
    	if ( $gmw['ID'] == 1 && $gmw['page_load_results_trigger'] == 1 ) {
    		$gmw['page_load_results']['address_filter'] = $mypostcode;
    	}
    
    	return $gmw;
    }
    add_filter( "gmw_pt_default_form_values" , 'gmw_formload', 99 );

    (Delayed reply from me)

    This worked perfectly! Thank you 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Possible to set the default 'starting address' on the fly?’ is closed to new replies.