3

Here is a question I have spent over 3 hours attempting to solve but each approach I take ends up not working out for me.

All I am attempting to do is utilize this opensource ajax calendar script:

and have the entries display all posts within a specific post type. For each of the posts within this event post type I have a custom metabox with the following custom fields:

  • event category
  • event start date
  • event start time
  • event end date
  • event end time

At the most basic level I just need each post to show up within the applicable calendar box based on the "event start date" and "event start time" and link to the applicable event post details page.

In an ideal situation I was looking to have each event category with its own color and have each event span multiple days if the applicable event has an "event_end_date" that is different than the start date.

Has anyone done this before and can past the applicable code to get either of these in place. I feel this would be highly valuable to the WordPress community as well.

1 Answer 1

5

FullCalendar is a nice find.

Looks to me like you'll need to write a shortcode (which I show how to do here):

And then generate the code to call the FullCalendar within the shortcode.

After that you'll need to write code to generate a Javascript array or have it references a JSON feed:

Here's code you can put into a standalone .PHP file which you could call /fullcalendar-json-feed.php or whatever you like. The code queries a custom post types called event which will run in the root directory of your website and will generate a JSON feed and it assumes you've got some custom fields needed to populate the array/feed. (I'm going to leave the rest of the query and custom field details to you. Note I didn't actually test this with FullCalendar so it might take a bit of tweaking):

<?php
/*
* See: https://wordpress.stackexchange.com/questions/1447/
*
*/
include "wp-load.php";
global $wpdb;
header('Content-Type:application/json');
$events = array();
$result = new WP_Query('post_type=event&posts_per_page=-1');
foreach($result->posts as $post) {
  $events[] = array(
    'title'   => $post->post_title,
    'start'   => get_post_meta($post->ID,'_start_datetime',true),
    'end'     => get_post_meta($post->ID,'_end_datetime',true),
    'allDay'  => (get_post_meta($post->ID,'_all_day',true) ? 'true' : 'false'),
    );
}
echo json_encode($events);
exit;

You can generate the array option with very similar code to that above. Still, this is going to take a bit of coding for you to get right. Maybe you just want to use a solution that's already built? Here's a Q&A discussion about calendars for WordPress:

3
  • Mike, do you ever sleep or do you just stay awake waiting for me to post the next one :) Thanks man, I will give this a shot and I hope I can somehow figure out a way to get things to work based of your starting point. Commented Sep 7, 2010 at 10:24
  • Mike, on a different topic; based on your obvious experience I think you could provide a quick solution to another question I posted today which I just updated with new findings. Would you mind taking a look: link: wordpress.stackexchange.com/questions/1449/… Commented Sep 7, 2010 at 10:35
  • @NetConstuctor.com: Note: I haven't answered all your questions. I'm prepping to make you dependent on me so next time you'll have to hire me! ;-) ;-) ;-) j/k. As for the other question, it's longer than I can tackle right now. I'll be spending less time on the site in the next few days as I work on client projects... Commented Sep 8, 2010 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.