Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Eyal Fitoussi

    (@ninjew)

    Hi Paul,

    I apologize for the trouble.

    I received a support ticket from you 2 days ago, on March 6, and I replied to it within a couple of hours.

    In your support ticket, you referred me to a large file that seems to contain many different custom functions. So I asked you to provide me with the exact custom function that you are having issues with within that file.

    I haven’t heard back from you since my reply.

    Thread Starter Paul Maloney

    (@paul-m-uk)

    There has been no reply. I would have replied. I sent a support form and have emailed independently.

    gmw_update_post_location( $post_id, $postcode ); is my issue, it doesn’t work. I’ve tried full address, a short address, lat and lon and postcode only. I’ve even tried: gmw_update_post_location( $post_id, ‘90210’ ); for example

    I’ve tried it as a function and standalone. My google API is valid. It will not update the post location.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Please verify that your Google Maps Server API key is working properly ( if you haven’t done so already ). You can do so from the dashboard -> GEO my WP -> Tools -> API testing.

    It is possible that the plugin is working on the front end since it uses the Browser API key. But the gmw_update_post_location() function depends on the Server API key, and if that key is not set up properly the function won’t work.

    Thread Starter Paul Maloney

    (@paul-m-uk)

    Thread Starter Paul Maloney

    (@paul-m-uk)

    https://share.getcloudapp.com/kpuJkGKx – the locator works manually.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Thanks.

    Can you please provide me with the complete script that you are using?

    I would like to see where exactly the $post_id is coming from.

    Thread Starter Paul Maloney

    (@paul-m-uk)

    Sure:

    
    $my_post = array(
         //post info
    );
    
    wp_insert_post( $my_post );	
    $post_id = wp_insert_post( $my_post );
    gmw_update_post_location( $post_id, $postcode );
    
    
    Thread Starter Paul Maloney

    (@paul-m-uk)

    I’ve also emailed you the full codebase

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Thanks.

    This is what I see in the script, which is different than what you posted above:

    
    // saving to DB
    wp_set_object_terms( $post_id, $categories, 'custom_cat_event' );
    if ( ! function_exists( 'gmw_update_post_location' ) ) {
         gmw_update_post_location( $post_id, $postcode );
    }
    $post_id = wp_insert_post( $my_post );
    

    You placed the gmw_update_post_location() function before the wp_insert_post() function, which by my understanding the $post_id not yet exist when you pass it into GEO my WP’s function. You should probably place the function wp_insert_post() before gmw_update_post_location().

    Another thing is that you are running the function inside a loop. In that case, you should place a delay of about 2 seconds ( sleep(2) ) after each time the gmw_update_post_location() is executed. That function runs the geocoder and you need to have a short delay when batch geocoding.

    And, To first verify that the function gmw_update_post_location() is working at all, you can place it at the top of the functions.php file and pass a specific post ID and a specific address to it. Then reload your site, remove the function, and check if the location of that post was updated. This way you will be able to know if the issue is with the function or with your script.

    Let me know how it goes.

    • This reply was modified 2 years, 4 months ago by Eyal Fitoussi.
    Thread Starter Paul Maloney

    (@paul-m-uk)

    I ran it in functions and it works.

    The gmw_update_post_location was below the insert post, I’ve been moving things around to try and make it work.

    I now have:

    
    function gmw_update_post_type_post_location(  $post_id ) {
    	// varify that address exists.
    	if ( empty( $postcode ) ) {
    		return;
    	}
    
    	// verify the updater function.
    	if ( ! function_exists( 'gmw_update_post_location' ) ) {
    		return;
    	}
    
    	//run the udpate location function
    	gmw_update_post_location( $post_id, $postcode );
    	 sleep(2);
    }
    

    in my functions file and used

    
    wp_insert_post( $my_posts );		
    $post_id = wp_insert_post( $my_posts );
    add_action( 'save_post_event', 'gmw_update_post_type_post_location' );

    in the plugin file, still no luck.

    • This reply was modified 2 years, 4 months ago by Paul Maloney.
    Plugin Author Eyal Fitoussi

    (@ninjew)

    The above won’t work since the $postcode does not exist inside the gmw_update_post_type_post_location() function.

    Try this:

    1. replace the script in your functios.php file with the below:

    
    function gmw_update_post_type_post_location(  $post_id ) {
    
            $postcode = get_post_meta( $post_id, 'gmw_postcode', true );
    
    	// varify that address exists.
    	if ( empty( $postcode ) ) {
    		return;
    	}
    
    	// verify the updater function.
    	if ( ! function_exists( 'gmw_update_post_location' ) ) {
    		return;
    	}
    
    	//run the udpate location function
    	gmw_update_post_location( $post_id, $postcode );
    
    	sleep(2);
    }
    add_action( 'save_post_event', 'gmw_update_post_type_post_location' );
    

    2. In your plugin file replace:

    
    wp_insert_post( $my_posts );		
    $post_id = wp_insert_post( $my_posts );
    add_action( 'save_post_event', 'gmw_update_post_type_post_location' );
    

    with:

    
    $post_id = wp_insert_post( $my_posts );
    update_post_meta( $post_id, 'gmw_postcode', $postcode );
    

    Let me know if this works.

    Plugin Author Eyal Fitoussi

    (@ninjew)

    Hi Paul,

    Just checking if you have tried the above and if it works.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘gmw_update_post_location’ is closed to new replies.