• Hi
    I’m using the plugin but the table remains empty. My field is address.
    Do you have a solution ?
    Thanks

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author raiserweb

    (@raiserweb)

    Are you using ACF?

    // bail early if no ACF data
    if( empty($_POST[‘acf’]) ) {
    return;
    }

    Thread Starter jeff2mars

    (@jeff2mars)

    yes im using ACF, and my google map field is named address in acf.

    You agree that I should let everything in the acf radius search folder even the functions.php ?

    Plugin Author raiserweb

    (@raiserweb)

    How you mean? Have you added this is a plugin? Yes the functions.php needs to be included – it contains the hook the will catch a post save, and update the address long lat in the table. ( function acf_google_maps_search_save_post( $post_id ) { )

    The plugin is small – I would recommend browsing the plugin files, and taking a look.

    Thread Starter jeff2mars

    (@jeff2mars)

    yes ok it’s a plugin, then it’s well installed like other plugins but the table is still empty. Does it work with products ? My address field is only filled for some products, not for all… may it be the problem ?

    Plugin Author raiserweb

    (@raiserweb)

    It should work for products, since they are posts

    To debug, please check that the action is firing (located in advanced-custom-fields-google-maps-search.php )

    // save post
    add_action(‘acf/save_post’, ‘acf_google_maps_search_save_post’, 20);

    Then check that this function has the correct data (located in functions.php)

    function acf_google_maps_search_save_post( $post_id ) {

    // bail early if no ACF data
    if( empty($_POST[‘acf’]) ) {
    return;
    }

    $address = get_field( ‘address’, $post_id );

    if( $address ){

    $acf_gms = new acf_gms;

    $data = [
    ‘post_id’ => $post_id,
    ‘lng’ => $address[‘lng’],
    ‘lat’ => $address[‘lat’],
    ];

    $acf_gms->save( $data );
    }

    }

    Thread Starter jeff2mars

    (@jeff2mars)

    i’m sorry but how could I check if the action is firing ?

    Plugin Author raiserweb

    (@raiserweb)

    You can perform the action on the front end (ie save the post), and add a var_dump + exit in the php function (acf_google_maps_search_save_post) to see if the browser displays the var_dump.

    This plugin is intended for developers only

    Thread Starter jeff2mars

    (@jeff2mars)

    I modify the following code, it’s showing nothing special

    function acf_google_maps_search_save_post( $post_id ) {
    
       // bail early if no ACF data
       if( empty($_POST['acf']) ) {
    	   return;
       }	
       
    
    	$address = get_field( 'address', $post_id );
    	
    	if( $address ){
    			
    		$acf_gms = new acf_gms;	
    		
    		$data = [
    			'post_id'	=> $post_id,
    			'lng'		=> $address['lng'],
    			'lat'		=> $address['lat'],
    		];
    		var_dump($address); exit;
    		$acf_gms->save( $data );		
    		
    	}
       
    
    }
    • This reply was modified 7 years, 1 month ago by jeff2mars.
    Plugin Author raiserweb

    (@raiserweb)

    Try this first. If no var dump, then you know the hook is not firing.

    function acf_google_maps_search_save_post( $post_id ) {

    var_dump($address); exit;

    // bail early if no ACF data
    if( empty($_POST['acf']) ) {
    return;
    }

    $address = get_field( 'address', $post_id );

    if( $address ){

    $acf_gms = new acf_gms;

    $data = [
    'post_id' => $post_id,
    'lng' => $address['lng'],
    'lat' => $address['lat'],
    ];

    $acf_gms->save( $data );

    }

    }

    Plugin Author raiserweb

    (@raiserweb)

    Sorry I mean this:

    function acf_google_maps_search_save_post( $post_id ) {

    echo ‘test’; exit;

    // bail early if no ACF data
    if( empty($_POST[‘acf’]) ) {
    return;
    }

    $address = get_field( ‘address’, $post_id );

    if( $address ){

    $acf_gms = new acf_gms;

    $data = [
    ‘post_id’ => $post_id,
    ‘lng’ => $address[‘lng’],
    ‘lat’ => $address[‘lat’],
    ];

    $acf_gms->save( $data );

    }

    }

    Thread Starter jeff2mars

    (@jeff2mars)

    “test is displayed.

    and with var_dump :

    Notice: Undefined variable: address in C:\wamp64\www\wp-content\plugins\acf-google-maps-radius-search\functions.php on line 3
    C:\wamp64\www\wp-content\plugins\acf-google-maps-radius-search\functions.php:33:null

    Plugin Author raiserweb

    (@raiserweb)

    Ok, since test is displayed, it shows that the function is firing when you save a product.

    So I’m afraid I’ll have to leave the rest to you to debug. Maybe $_POST[‘acf’] is empty

    Thread Starter jeff2mars

    (@jeff2mars)

    yes, when I try do display $_POST[‘acf’] I get

    Notice: Undefined index: acf in C:\wamp64\www\wp-content\plugins\acf-google-maps-radius-search\functions.php on line 33

    I don’t know why…

    Plugin Author raiserweb

    (@raiserweb)

    Not sure. Try commenting this if statement

    function acf_google_maps_search_save_post( $post_id ) {

    // bail early if no ACF data
    //if( empty($_POST[‘acf’]) ) {
    //return;
    //}

    $address = get_field( ‘address’, $post_id );

    if( $address ){

    $acf_gms = new acf_gms;

    $data = [
    ‘post_id’ => $post_id,
    ‘lng’ => $address[‘lng’],
    ‘lat’ => $address[‘lat’],
    ];

    $acf_gms->save( $data );

    }

    }

    Thread Starter jeff2mars

    (@jeff2mars)

    ok when commenting, a line is added to the table !

    but the older posts that have an address are not inserted in the table (assuming that the function update_historic_post_gm_data() is supposed to do that)

    • This reply was modified 7 years, 1 month ago by jeff2mars.
Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Table remain empty’ is closed to new replies.