GEO my WP & WP User Front-end Integration

The script below ( Thank you @Alvin Bond for posting the script ) you can use to create GEO my WP locations using WP User Front-end plugin. When creating new posts or updating existing posts using Wp User Front-end the address field in the form will be geocoded and saved into GEO my WP custom table in database which will make the post searchable using GEO my WP search forms.

All you need to do is add an address field to the WP user Front-end form ( if you don't have one already ) and copy paste the script below to the functions.php file of your theme. After done so change the custom field "cd_address" that in the script to the name of the address custom field of your form.


function gmw_update_location_via_wpuf(  $post_id ) {

	//make sure we have post ID
	if ( !$post_id )
		return;

	//change meta_field_name to the custom field of the address field
	$address = get_post_meta( $post_id, 'cf_address', true );

	//include geocoder file
	include_once( GMW_PT_PATH .'/includes/gmw-pt-update-location.php' );

	if ( function_exists( 'gmw_pt_update_location' ) ) {
		//setup geocoder args
		$args = array(
				'post_id'         => $post_id,
				'post_type'       => get_post_type( $post_id ), // change post_type to your own
				'post_title'      => get_the_title( $post_id ),
				'address'         => $address
		);
		//run geocoder function
		gmw_pt_update_location( $args );
	}
}
//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_add_post_after_updated', 'gmw_update_location_via_wpuf', 10, 1 );