I'm facing a problem tonight with WordPress ACF and some if / else conditions. Here is my code :
<?php
if( get_field('latitude_du_terrain') && get_field('longitude_du_terrain') ) {
$acf_latitude = get_field('latitude_du_terrain');
$acf_longitude = get_field('longitude_du_terrain');
$acf_category = get_field('terrains_categorie');
$carte = sprintf(
'[display_map zoom=12 height=600 marker1="%1$s | %2$s | hello world | This is first marker info window message | %3$s"]',
$acf_latitude,
$acf_longitude,
$acf_category
);
echo do_shortcode( $carte );
} else {
$acf_category = get_field('terrains_categorie');
$CURRENTPOST_LAT = get_post_meta(get_the_ID(),'_wpgmp_metabox_latitude',true);
$CURRENTPOST_LON = get_post_meta(get_the_ID(),'_wpgmp_metabox_longitude',true);
echo $acf_category;
$carte = sprintf(
'[display_map zoom=12 height=600 marker1="%1$s | %2$s | hello world | This is first marker info window message | %3$s"]',
$CURRENTPOST_LAT,
$CURRENTPOST_LON,
$acf_category
);
echo do_shortcode( $carte );
}
?>
Right now my problem is in the else portion of the code.
ACF is not displaying the "terrains_categorie" custom field. It seems that there is a problem accessing this field from this part of the code.
I tried with an another ACF function, "get_sub_field", but it's not working too.
I'm probably missing something here... but I don't know what.
Thanks in advance for your help!