• Resolved kartguru

    (@kartguru)


    Hi

    I have had success using mapping to copy coordinates to Simple Location postmeta (using coordinates) but am trialling GEO My WP for some extra functionality I’d like to introduce. I believe GEO My WP has a Posts Location function for such integrations. Geo My WP does not store the data under postmeta. My code is not capturing the necessary data.

    Running
    Post my CF7 Form
    Smart Grid for CF7
    CF7 Geo Map
    GEO My WP

    In functions.php (per example in above link).

    function gmw_update_post_type_post_location(  $post_id ) {
    	// Return if it's a post revision.
    	if ( false !== wp_is_post_revision( $post_id ) ) {
    		return;
    	}
    	// check autosave.
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    		return;
    	}
    	// check if user can edit post.
    	if ( ! current_user_can( 'edit_post', $post_id ) ) {
    		return;
    	}
    	// get the address from the custom field "address".
    	$address = $form_data['address-my-location'];
    	// verify that address exists.
    	if ( empty( $address ) ) {
    		return;
    	}
    	// verify the updater function.
    	if ( ! function_exists( 'gmw_update_post_location' ) ) {
    		return;
    	}
    	//run the update location function
    	gmw_update_post_location( $post_id, $address );
    }
    
    //execute the function whenever post type is being updated
    add_action( 'save_post_post', 'gmw_update_post_type_post_location' );

    As a check I have mapped this same info into the Post Content and this works as expected.

    Appreciate any assistance you can give.

    Cheers

    – michael

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    As a check I have mapped this same info into the Post Content and this works as expected.

    where are you trying to map it to? A post meta-field?

    You’ll probably need to use a filter and programmatically map it.

    I have never used either of those plugins so I can’t help you beyond general guidance.

    Thread Starter kartguru

    (@kartguru)

    Thanks for responding @aurovrata and thanks for the sweet plugin.

    Using the below code I was able to pass on the form data to GEO My WP

    add_action('cf7_2_post_form_submitted_to_post', 'new_post_mapped',10,4);
    function new_post_mapped($post_id, $cf7_form_data, $cf7form_key, $submitted_files){
    	// ref https://docs.geomywp.com/article/154-posts-locator-function-gmwupdatepostlocation
    	if ( false !== wp_is_post_revision( $post_id ) ) {
    		return;
    	}
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    		return;
    	}
    	if ( ! current_user_can( 'edit_post', $post_id ) ) {
    		return;
    	}
    	$address = $cf7_form_data['address-my-location'];
    	if ( empty( $address ) ) {
    		return;
    	}
    	if ( ! function_exists( 'gmw_update_post_location' ) ) {
    		return;
    	}
    	gmw_update_post_location( $post_id, $address );
    }
    Plugin Author Aurovrata Venet

    (@aurovrata)

    Using the below code I was able to pass on the form data to GEO My WP

    neat! Glad you got it working!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Capturing form_data for GEO My WP.’ is closed to new replies.