I have a 'single' page for individual workshop events and i'm tying to create an 'add to calendar' functionality. Right now i have a link setup, which passes the current post ID in a query string to the PHP file that generates the iCal file. I'm pretty sure I should be able to generate such a file from a wp_query, but i know my code is probably grotesquely incorrect. I've been working on this all day and can't seem to make any other post i've found on the matter work. Any help would really be appreciated. I'm semi-new to wordpress so be gentle!
Here's the file:
//allow access to the wp_query method:
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-blog-header.php' );
//get the post ID from the incoming query string:
$workshop_id = @$_GET['workshop_id'];
$args = array(
'p' => $workshop_id,
'post_type' => 'any');
$the_query = new WP_Query($args);
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) :
$the_query->the_post();
$workshop = array(
'workshop_title' => get_field('workshop');
);
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=calendar.ics");
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//Foobar Corporation//NONSGML Foobar//EN\n";
echo "METHOD:REQUEST\n"; // requied by Outlook
echo "BEGIN:VEVENT\n";
echo "UID:".date('Ymd').'T'.date('His')."-".rand()."-example.com\n"; // required by Outlok
echo "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
echo "DTSTART:20080413T000000\n";
// echo "SUMMARY:{$workshop['workshop_title']}\n";
echo "DESCRIPTION: this is just a test\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
endwhile;
endif;
?>