friendsoftheCT

WP Full Calendar Snippet

Feb 19th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1.         //Create our own loop here and tamper with the where sql for date ranges, as per http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters
  2.         function wpfc_temp_filter_where( $where = '' ) {
  3.             $where .= " AND post_date >= '".date("Y-m-d", $_REQUEST['start'])."' AND post_date < '".date("Y-m-d", $_REQUEST['end'])."'";
  4.             return $where;
  5.         }
  6.         add_filter( 'posts_where', 'wpfc_temp_filter_where' );
  7.         $the_query = new WP_Query( $args );
  8.         remove_filter( 'posts_where', 'wpfc_temp_filter_where' );
  9.         //loop through each post and slot them into the array of posts to return to browser
  10.         while ( $the_query->have_posts() ) { $the_query->the_post();
  11.             $color = "#a8d144";
  12.             $post_date = substr($post->post_date, 0, 10);
  13.            
  14.             $post_timestamp = strtotime($post->post_date);
  15.             if( empty($item_date_counts[$post_date]) || $item_date_counts[$post_date] < $limit ){
  16.                 $title = $post->post_title;
  17.                 $item = array ("title" => $title, "color" => $color, "start" => date('Y-m-d\TH:i:s', $post_timestamp), "end" => date('Y-m-d\TH:i:s', $post_timestamp), "url" => get_permalink($post->ID), 'post_id' => $post->ID );
  18.                 $items[] = apply_filters('wpfc_ajax_post', $item, $post);
  19.                 $item_date_counts[$post_date] = (!empty($item_date_counts[$post_date]) ) ? $item_date_counts[$post_date]+1:1;
  20.             }elseif( empty($item_dates_more[$post_date]) ){
  21.                 $item_dates_more[$post_date] = 1;
  22.                 $day_ending = $post_date."T23:59:59";
  23.                 //TODO archives not necesarrily working
  24.                 $more_array = array ("title" => get_option('wpfc_limit_txt','more ...'), "color" => get_option('wpfc_limit_color','#fbbe30'), "start" => $day_ending, 'post_id' => 0, 'allDay' => true);
  25.                 global $wp_rewrite;
  26.                 $archive_url = get_post_type_archive_link($post_type);
  27.                 if( !empty($archive_url) || $post_type == 'post' ){ //posts do have archives
  28.                     $archive_url = trailingslashit($archive_url);
  29.                     $archive_url .= $wp_rewrite->using_permalinks() ? date('Y/m/', $post_timestamp):'?m='.date('Ym', $post_timestamp);
  30.                     $more_array['url'] = $archive_url;
  31.                 }
  32.                 $items[] = apply_filters('wpfc_ajax_more', $more_array, $post_date);
  33.             }
  34.         }
  35.         echo json_encode(apply_filters('wpfc_ajax', $items));
  36.         die(); //normally we'd wp_reset_postdata();
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment