I want to output a list of locations as a table and mark them up on a map. For this I have created a content type in WordPress with Pods with a property "Address". With a Pods shortcode, I am able to have the table created and list all the entries. With another Pods shortcode, I am able to generate a Leaflet shortcode.
The problem is that the Leaflet shortcode is output to the frontend, but is not interpreted by Leaflet as a map. If I use the Leaflet shortcode generated by Pods from the frontend in the backend, the map works as desired.
I’m afraid the problem arises because the shortcode generated by a shortcode is not taken into account and implemented.
I have created a WordPress page and noted the following shortcode:
[pods name="locations"]<br /><br />[/pods][pods name="locations"]<br />[leaflet-marker address="{@locations-address}"]<br />[/pods]
A correct shortcode is output in the frontend:
[leaflet-marker address="Ingolstädter Str. 101, 80939 München"]
In consultation with the developer of the Leaflet plugin for WordPress, I tried to insert the function with XYZ PHP code:
<?php
$a = do_shortcode( '[pods name="locations"][leaflet-marker]' . '[' . 'leaflet-marker address={@locations-address}' . ']' . '<br>[/pods]');
echo "[leaflet-map] $a [leaflet-marker]";
?>
The result is better, as the map is generated largely as desired, but when I insert the XYZ PHP code into the WordPress page, no map is output.
2
Answers
I have found a solution in the meantime. The keyword is nested shortcodes (https://codex.wordpress.org/Shortcode_API) and the function "do_shortcode()".
Using a custom WordPress plug-in to run a script and output it as a custom shortcode, I was able to generate the map as desired. For this I used the following code. It is important to note that "do_shortcode()" must be used twice, first for Pods and then for Leaflet.
By default including a shortcode within a Pods shortcode will not work. If you need this functionality to work, you need to include the following constant in your wp_config.php file:
Then, if you need to parse a shortcode within the Pods template, custom template or within your Pods shortcode, just add
shortcodes=1
to the Pods shortcode.Or you can use the filter below to have it always enabled:
All these are explained at Pod’s documentation.