I'm very new to this, so please go easy on me if this is a dumb question.
I am building a site with events manager and geo my wordpress plugins. I want a user to be able to input their autofill location (via GMW) and have the calendar in EM output only events a certain distance from that location. I have already gotten (with handholding) to a point where I have a shortcode that spits out the coordinates of the location entered. The EM full calendar shortcode takes an attribute called 'near' which takes coordinates and subsequently outputs the desired calendar.
Code at the moment:
[fullcalendar near=[gmw_current_latlng] near_distance=20]
with [gmw_current_latlng] normally returning the lat and long separated by a comma. Normally, the near att takes say 50.111123,-45.234 etc.
My problem is that it seems that I cannot get what I want with this hardheaded approach. Again, I'm very new to coding and don't know much, but I've been working on this problem for weeks and have not found an answer. I've tried many different routes, but this way has brought me oh so close to where I want to be.
The GMW dev said this about the problem:
"The thing is that I am not even sure if you can pass a value to a shortcode using another shortcode. I’ve never tried this myself. The best way would be to use filters and a custom function to “inject” the coords directly into the calendar function."
If he is right and it's not possible, I have no idea how to carry out his second suggestion. Hopefully I can get this sorted out because frankly, my site depends on it working.
Of course you can pass a shortcode as an attribute of another shortcode. The only problem is, attributes doesn't pass [ or ]. So you have replace convert those bracket them with their html entry.
Replace
[
with[
and]
with]
and you should be fine. Here is an example.Then put this on your editor
See we are passing a shortcode
[bar]
as an attribute of[foo]
. So the output should be -Foo = Something and bar = Output from bar shortcode
I know it looks a bit nasty but it will do the trick.
As @Jeppe mentioned, you can do Nested Shortcodes:
But the parser does not like shortcode values as attributes in other shortcodes.
It sounds like you're reliant on a few plugins and their shortcodes, so I don't suggest editing those shortcodes - but if you look at the Shortcode API it's pretty easy to add you own. For simplicity's sake, this example won't contain the "proper" methods of making sure the shortcodes exist/plugins are installed etc, and will just assume they are.
Provided
[gmw_current_latlng]
returns a useable format for your[fullcalendar]
shortcode, you should now be able to use your new shortcode that combines the two:[calendar_with_latlng]
or you can also add thenear_distance
attribute:[calendar_with_latlng near_distance=44]
.You would just need to put the above functions into your
functions.php
, create a Simple Plugin, or save them to a file and add it in your Must-Use Plugins directory.