I'm trying to create a link to add dates to google calendar from Advanced Custom Fields with the Date and Time Picker Field plugin but I think I'm tying myself up in knots with it.
So far this is where I'm at
<?php
$format = "Ymd\THis\Z";
$starttime = get_field('start');
$endtime = get_field('end');
$eventstart = date($format , $starttime);
$eventend = date($format , $endtime);?>
<a href="http://www.google.com/calendar/event?
action=TEMPLATE
&text=[<?php the_title(); ?>]
&dates=[start-custom format='<?php echo $eventstart ;?>']/
[end-custom format='<?php echo $eventend ;?>']
&details=[<?php echo (get_field('summary'));?>]
&location=[address]
&trp=false
&sprop=
&sprop=name:"
target="_blank" rel="nofollow">Add to my calendar</a>
The $eventstart
and $eventend
return what seems to be valid formats (20151231T120000Z & 20151231T140000Z respetively) but when linking through to google calendar it simply loads google calendar on today's date with the ur
https://calendar.google.com/calendar/render?action=TEMPLATE&text=[test+event]&dates=[start-custom+format%3D%2720151231T120000Z%27]/[end-custom+format%3D%2720151231T140000Z%27]&details=[]&location=[location]&trp=false&sprop&sprop=name:&pli=1&sf=true&output=xml#main_7
Can anyone tell me where I might be going wrong?
I'm a complete idiot! Writing the code within the link correctly fixes it:
<a href="http://www.google.com/calendar/event?
action=TEMPLATE
&text=<?php the_title(); ?>
&dates=<?php echo $eventstart ;?>/<?php echo $eventend ;?>
&details=<?php echo (get_field('summary'));?>
&location=<?php echo (get_field('address'));?>"
target="_blank" rel="nofollow">Add to my calendar</a>