Home Forums Plugin Support WP User Frontend (Free Version) Google Maps – Store and retrieve address in Google Maps Field

This topic is: resolved

This topic contains 5 replies, has 5 voices, and was last updated by  erimathi 4 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6962

    chrishanratty
    Participant
    Post count: 7

    Hello,

    I wanted the google maps field to store an address in a custom field I could use as a string to present in the post template. But I also wanted to have the address called back into the google maps field “Find address” box when the user edits the post.

    I was able to achieve this using the following hack.

    STEP 1 – Use the code Tareq gave me to store the Find Address in a custom field.
    I put this code in my theme custom functions.

    function wpufe_inesrt_address( $post_id ) {
    if ( isset( $_POST['find-address'] ) ) {
    update_post_meta( $post_id, ‘cf_address’, $_POST['find-address'] );
    }
    }
    add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_inesrt_address’ );
    add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_inesrt_address’ );

    STEP 2 – Tweak this file;

    plugins/wp-user-frontend-pro/class/render-form.php

    (hope nobody on the awesome wedevs team is offended!)

    Find this line of code, it should be near the end near of the file in a function called
    “Function Map”

    <input id="wpuf-map-add-<?php echo $attr['name']; ?>" type="text" value="" name="find-address" placeholder="<?php _e( 'Type an address to find', 'wpuf' ); ?>" size="30" />

    Replace it with this code…

    <input id="wpuf-map-add-<?php echo $attr['name']; ?>" type="text" value="<?php echo get_post_meta( $post_id, 'cf_address', true ); ?>" name="find-address" placeholder="<?php _e( 'Type an address to find', 'wpuf' ); ?>" size="30" />

    That will call the stored address from the CF_ADDRESS custom field using Get_Post_Meta function and place it into the Find Address box during the rendering of the Google Map field in forms.

    It works for me so far. Sorry if its an inelegant way of doing this but I am only new at this PHP business.

    Of course this tweak may get blown away with updates to the plugin, so you will have to re-apply it after updates.

    Love this plugin. Thanks.

    Chris.

    #6963

    chrishanratty
    Participant
    Post count: 7

    Oh no my code went off the page. Here it is again

    Find this;

    <input id="wpuf-map-add-<?php echo $attr['name']; ?>" type="text" value="<?php echo
    get_post_meta( $post_id, 'cf_address', true ); ?>" name="find-address" placeholder="<?php
     _e( 'Type an address to find', 'wpuf' ); ?>" size="30" />

    Replace it with this….

    <input id="wpuf-map-add-<?php echo $attr['name']; ?>" type="text" value="<?php echo
     get_post_meta( $post_id, 'cf_address', true ); ?>" name="find-address" placeholder="<?php
     _e( 'Type an address to find', 'wpuf' ); ?>" size="30" />
    #6973

    Tareq Hasan
    Keymaster
    Post count: 2831

    Hope that will help some others 🙂

    #7829

    jman057
    Participant
    Post count: 16

    Hi Tareq,

    I can't seem to get that function to work. I want to retain the written address to show in the post.

    I've tried sending to to a different custom field other than “address”, I've tried embedding it in a different function that I know executes, and I've tried removing the “if” conditional. None of the options seem to work.

    Any ideas? It doesnt need to go back to the address field if that helps?

    Thanks!

    Jamie

    #14160

    Denis
    Participant
    Post count: 165

    change ‘ to ‘

    function wpufe_insert_address( $post_id ) {
    if ( isset( $_POST['find-address'] ) ) {
    update_post_meta( $post_id, 'your-custom-field-name', $_POST['find-address'] );
    }
    }
    add_action( 'wpuf_add_post_after_insert', 'wpufe_insert_address' );
    add_action( 'wpuf_edit_post_after_update', 'wpufe_insert_address' );
    #16207

    erimathi
    Member
    Post count: 1

    Hi, cant seem to get this to work. If i understand correctly you are trying to get the address field to print out as a string in addition to the map? In that case where is the address supposed to print?

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Google Maps – Store and retrieve address in Google Maps Field’ is closed to new replies.