• Hi team,

    I am building a website which needs to let user input their location while publishing post and at the same time be able to view post on front-end.

    Currently we have tested both WP User Frontend and ACF for users to input location while publishing post, and both work.

    However, in order to display these post on a map, we need to pass the LAT and LON values to GMWP. Do you have way to input the LAT and LON from WPUF or ACF’s location field or both?

    Thanks.

    Gey

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi Gey, I’ve run into the same issue. I’ve seen that under the Import/Export tab of the GMWP settings, you can map post fields to GMWP LAT and LON fields to import the data when desired, on-demand. I’d obviously prefer a direct way to connect these fields, but don’t see a way of doing that via plugin settings alone.

    I’m also not sure how WPUF stores location information when a post is submitted from the front end. I see the following data in the AJAX submit calls:
    “location: Carrer del Llatzeret, 11, 08005 Barcelona, Spain || 41.4029902 || 2.2014224” – but that data doesn’t seem to be stored on the post, also I wouldn’t know how to extract LAT and LON values from the data. GWMP doesn’t recognise any location information on the post.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Hey @geylang666 and @creatino,

    Try this tutorial and see if it works for you.

    It should, but it has been a while since I wrote the tutorial and it is possible that the hooks it uses had changed in the WP User Front End plugin since then.

    I hope this helps.

    I use this:

    function update_GEOmyWP( $post_id, $form_id ) { 
    // check the right FORM
    if ( $form_id != 154 ) { // your form ID
    return;
    }
    // make sure post ID exists.
    if ( ! $post_id ) {
    return;
    } 
    // verify the updater function.
    if ( ! function_exists( 'gmw_update_post_location' ) ) {
    return;
    }
    	
    if ( isset( $_POST['rockspot_place'] ) ) { // Your fieldkey
    	
    list( $rs_address, $rs_lat, $rs_lng ) = explode( '||', $_POST['rockspot_place'] );
    list( $rs_street, $rs_place, $rs_country ) = explode( ',', $rs_address );
    list( $rs_postcode, $rs_city ) = explode( ' ', trim( $rs_place ), 2 );
     
    $location = array(
    'lat' => (float)$rs_lat,
    'lng' => (float)$rs_lng
    );
     
    //run the udpate location function
    gmw_update_post_location( $post_id, $location );
    }
    }
    add_action( 'wpuf_add_post_after_insert', 'update_GEOmyWP', 10, 2 );
    add_action( 'wpuf_edit_post_after_update', 'update_GEOmyWP', 10, 2 );
    • This reply was modified 4 years, 7 months ago by DenisCGN. Reason: To much code
    • This reply was modified 4 years, 7 months ago by DenisCGN.
    Thread Starter geylang666

    (@geylang666)

    Thanks all!

    <EXPLODE> Muchas gracias amigos, much appreciated. </EXPLODE>

    Hey @ninjew I followed your basic approach but using coordinates instead of address, and wrote the following:

    function gmw_update_location_via_wpuf($post_id) {
    	// make sure post ID exists.
    	if ( ! $post_id ) {
    		return;
        }
    
    	// verify updater function.
    	if ( function_exists( 'gmw_update_post_location' ) ) {
    		// change meta_field_name to the custom field of the address field.
    	    $locationMeta = get_post_meta( $post_id, 'location', true );
    		$coordinates = array(
    			"lat" => (float)$locationMeta["lat"],
    			"lng" => (float)$locationMeta["lng"]
    		);
    		//run geocoder function
    		gmw_update_post_location( $post_id, $coordinates );
    	}
    }
    
    //update data of new post
    add_action('wpuf_add_post_after_insert', 'gmw_update_location_via_wpuf', 10, 1 );
    //update data when post updated
    add_action('wpuf_edit_post_after_update', 'gmw_update_location_via_wpuf', 10, 1 );

    Everything is firing fine, but the location doesn’t update in . I started debugging to follow why, and got as far as:

    [21-Apr-2020 09:22:06 UTC] 1276
    [21-Apr-2020 09:22:06 UTC] GMW – Posting
    [21-Apr-2020 09:22:06 UTC] GMW – Defaulted to post nameasdasd
    [21-Apr-2020 09:22:06 UTC] Updating location
    [21-Apr-2020 09:22:06 UTC] GMW – gmw_update_location
    [21-Apr-2020 09:22:06 UTC] GMW – gmw_update_location – array recognised
    [21-Apr-2020 09:22:06 UTC] GMW – gmw_update_location – array lat and lng found
    [21-Apr-2020 09:22:06 UTC] GMW – $geo_addressArray
    (
    [lat] => 40.71791458474
    [lng] => -73.962794899278
    )
    [21-Apr-2020 09:22:06 UTC] GMW – gmw_update_location – Geocoding failed

    Before I start debugging in class-gmw-geocoder.php, any stupid mistakes I may be making in the encoding of the lat and lng? I’m a total newbie to PHP so probably missing something stupid.

    BTW, regarding the hooks mentioned in your tutorial (thanks!):
    based on the info at https://wedevs.com/docs/wp-user-frontend-pro/developer-docs/actions/wpuf_edit_post_after_update/ I think wpuf_add_post_after_updated should be wpuf_edit_post_after_update

    Thread Starter geylang666

    (@geylang666)

    Hi @deniscgn , thanks for your guidance, but I would seek a little more help from you.
    I am not even a developer but just trying to figure out possibilities for my developers, hence my question will be so stupid but still I must ask…

    I placed your code in to the function.php of my theme folder, and updated accordingly. Is that the right thing to do? However, I am not seeing GMWP location updating.

    Thanks.

    Btw, @creatino have you got it working?

    Thread Starter geylang666

    (@geylang666)

    Hi @creatino

    I tried your code and it actually works! For post edited from WPUF’s frontend, the GMWP location did update! Thank you so much!

    However, as I am not developer, may I ask how can this work for update from admin panel also? Thanks again!

    @geylang666 Glad it worked for you, still not working on my side.

    You can edit location in admin screens by activating GMWP widget on the correct pages.

    Admin side menu > Geo My WP > Settings > Post locator > Post Types

    Select the post types where you would like to enable geotagging. GEO my WP Location section will be added to the “Edit Post” page of the selected post types.

    @geylang666 If you want the GMWP location to update after saving a post whose location was updated using the ACF map component in the admin, try this:

    function update_GMWP_location( $post_id ) {
        // Get newly saved values.
        $values = get_fields( $post_id );
    
        // Check the new value of a specific field.
        // replace 'location'  with your 'custom_field'
        $location = get_field('location', $post_id);
        if( $location ) {
            // make sure post ID exists.
    	if ( ! $post_id ) {
    		return;
        }
    	// verify updater function.
    	if ( function_exists( 'gmw_update_post_location' ) ) {
    		$coordinates = array(
    			"lat" => (float)$location["lat"],
    			"lng" => (float)$location["lng"]
    		);
    		gmw_update_post_location( $post_id, $coordinates );
    	}
        }
    }
    
    add_action('acf/save_post', 'update_GMWP_location');

    It fails for me at the same point as updating from the front end, so will probably work for you. Based on: https://www.advancedcustomfields.com/resources/acf-save_post/

    • This reply was modified 4 years, 7 months ago by creatino.

    @ninjew GoDaddy was sending the request to Google out from a different IP than the shared IP displayed in my cpanel… wish I’d actually bothered to check network traffic before debugging your code

    Thanks a million for the plugin can’t wait to have the first map live on the site.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Geo My WP integration with WPUF’ is closed to new replies.