I am buidling real-estate website, and try to create the following:
I use a map plugin (Leaflet Map), making it possible to create maps quickly in each post (property listing) via shortcodes. The shortcode i use, is (more or less) static for every listing, only the coordinates for lat and long change from property to property. It looks like this:
[leaflet-map lat=36.509880 lng=-4.876681 zoom=15 zoomcontrol scrollwheel="1"]
I am also using ACF (advanced custom fields) plugin for WP. I use it with each listing, having fields for size, area, amount of rooms ect. I also have 2 fields, one for latitude and one for longtitude - the values from these should go directly into the above seen shortcode, resulting in a map being shown on the frontend, with the correct location of the property listing. Normally i use the following shortcode to insert a value from any of my advanced custom fields into my post/listing page:
[acf field="name of the custom field"]
But inserting the acf shortcode(s) into the leaflet map shortcode, doesn't work:
[leaflet-map lat=[acf field="latitude"] lng=[acf field="longtitude"] zoom=15 zoomcontrol scrollwheel="1"]
Can anybody help me with a solution to how this can be achieved?
Thanks!
Inserted the acf shortcodes into the leaflet maps shortcode:
[leaflet-map lat=[acf field="latitude"] lng=[acf field="longtitude"] zoom=15 zoomcontrol scrollwheel="1"]
[leaflet-map lat=[acf field="latitude"] lng=[acf field="longtitude"] zoom=15 zoomcontrol scrollwheel="1"]
It sounds like it would be better to use the pass the queried ACF fields into the do_shortcode()
function.
Something along the lines of...
if (have_rows($field_name) :
while (have_rows($field_name) : the_row;
$latitude = get_field('latitude');
$longitude = get_field('longitude');
do_shortcode('[leaflet-map lat=' . $latitude . ' lng=' . $longitude . ' zoom=15 zoomcontrol scrollwheel="1"]');
endwhile;
endif;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.