GEO my WP & Formiable Pro Integration

This short script creates integration between GEO my WP and Formidable Pro plugins. With this integration new posts being created or existing posts being updated using Formidable Pro plugin via the front-end will be searchable using GEO my WP.
All you need is an address field in your form and the script below added to the functions.php file of your theme/child theme.

The script below will be executed using Formidable Pro hook when a form is being submitted. The address field submitted in the form will be geocoded and saved in GEO my WP table in database which will make the post searchable via GEO my WP search forms.

Copy paste the script below into the functions.php file of your theme and update the fields variable as needed.

The function is located in geo-my-wp/plugins/posts/includes/gmw-pt-update-location.php

function gmw_save_frm_post_data( $entry_id, $form_id ) {
	//change the value 3 to the form ID that you want to use.
	//this will make sure that the script runs only in the needed form
	if ( $form_id != 3 )
        global $frmdb;
	//get the ID of the new post created
	$post_id = $frmdb->get_var( $frmdb->entries, array('id' => $entry_id), 'post_id' );

	//setup arguments for GEO my WP geocoder function
	$args = array(
			'post_id'         => $post_id, //post ID
			'post_type'       => get_post_type( $post_id ), //post Type
			'address'         => $_POST['item_meta'][8], //address - change the value 8 to the address field ID of your form
			'additional_info' => array( 'phone' => false, 'fax' => false, 'email' => false, 'website' => false ),
			'map_icon'        => '_default.png',
	//include the file with the geocode function
	include_once( GMW_PT_PATH .'includes/gmw-pt-update-location.php' );
	//the function
	gmw_pt_update_location( $args );
//hook for new post created
add_action( 'frm_after_create_entry', 'gmw_save_frm_post_data', 50, 2 );
//hook when post updated
add_action( 'frm_after_update_entry', 'gmw_save_frm_post_data', 10, 2 );