Table remain empty
-
Hi
I’m using the plugin but the table remains empty. My field is address.
Do you have a solution ?
Thanks
-
Are you using ACF?
// bail early if no ACF data
if( empty($_POST[‘acf’]) ) {
return;
}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 ?
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.
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 ?
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 );
}}
i’m sorry but how could I check if the action is firing ?
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
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.
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 );
}
}
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 );
}
}
“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:nullOk, 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
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…
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 );
}
}
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.
-
This reply was modified 7 years, 1 month ago by
- The topic ‘Table remain empty’ is closed to new replies.