friendsoftheCT

My WP Full Calendar Modifications

Feb 19th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.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.               $start_post_date              =         get_post_meta( get_the_ID(), '_cmb_event_start_date', true);
  13.               $start_post_time              =         get_post_meta( get_the_ID(), '_cmb_event_start_time', true);
  14.               $end_post_date                =         get_post_meta( get_the_ID(), '_cmb_event_end_date', true);
  15.               $end_post_time                =         get_post_meta( get_the_ID(), '_cmb_event_end_time', true)
  16.  
  17.               $start_post_timestamp         =       strtotime( sprintf( '%s %s',
  18.                                                 gmdate(Y-m-d, $start_post_date)
  19.                                                 gmdate(H:i:s, $start_post_time)
  20.                                                 )
  21.                                                       );
  22.         $end_post_timestamp =         strtotime( sprintf( '%s %s',
  23.                                                 gmdate(Y-m-d, $end_post_date)
  24.                                                 gmdate(H:i:s, $end_post_time)
  25.                                                 )
  26.                                                 );
  27.             if( empty($item_date_counts[$post_date]) || $item_date_counts[$post_date] < $limit ){
  28.                 $title = $post->post_title;
  29.                 $item = array (
  30.                 "title" => $title,
  31.                 "color" => $color,
  32.                 "start" => date('Y-m-d\TH:i:s', $start_post_timestamp),
  33.                 "end" => date('Y-m-d\TH:i:s', $end_post_timestamp),
  34.                 "url" => get_permalink($post->ID), 'post_id' => $post->ID );
  35.                 $items[] = apply_filters('wpfc_ajax_post', $item, $post);
  36.                 $item_date_counts[$post_date] = (!empty($item_date_counts[$post_date]) ) ? $item_date_counts[$post_date]+1:1;
  37.             }elseif( empty($item_dates_more[$post_date]) ){
  38.                 $item_dates_more[$post_date] = 1;
  39.                 $day_ending = $post_date."T23:59:59";
  40.                 //TODO archives not necesarrily working
  41.                 $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);
  42.                 global $wp_rewrite;
  43.                 $archive_url = get_post_type_archive_link($post_type);
  44.                 if( !empty($archive_url) || $post_type == 'post' ){ //posts do have archives
  45.                     $archive_url = trailingslashit($archive_url);
  46.                     $archive_url .= $wp_rewrite->using_permalinks() ? date('Y/m/', $post_timestamp):'?m='.date('Ym', $post_timestamp);
  47.                     $more_array['url'] = $archive_url;
  48.                 }
  49.                 $items[] = apply_filters('wpfc_ajax_more', $more_array, $post_date);
  50.             }
  51.         }
  52.         echo json_encode(apply_filters('wpfc_ajax', $items));
  53.         die(); //normally we'd wp_reset_postdata();
  54.     }
Add Comment
Please, Sign In to add comment