Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- function wpfc_temp_filter_where( $where = '' ) {
- $where .= " AND post_date >= '".date("Y-m-d", $_REQUEST['start'])."' AND post_date < '".date("Y-m-d", $_REQUEST['end'])."'";
- return $where;
- }
- add_filter( 'posts_where', 'wpfc_temp_filter_where' );
- $the_query = new WP_Query( $args );
- remove_filter( 'posts_where', 'wpfc_temp_filter_where' );
- //loop through each post and slot them into the array of posts to return to browser
- while ( $the_query->have_posts() ) { $the_query->the_post();
- $color = "#a8d144";
- $post_date = substr($post->post_date, 0, 10);
- $post_timestamp = strtotime($post->post_date);
- if( empty($item_date_counts[$post_date]) || $item_date_counts[$post_date] < $limit ){
- $title = $post->post_title;
- $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 );
- $items[] = apply_filters('wpfc_ajax_post', $item, $post);
- $item_date_counts[$post_date] = (!empty($item_date_counts[$post_date]) ) ? $item_date_counts[$post_date]+1:1;
- }elseif( empty($item_dates_more[$post_date]) ){
- $item_dates_more[$post_date] = 1;
- $day_ending = $post_date."T23:59:59";
- //TODO archives not necesarrily working
- $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);
- global $wp_rewrite;
- $archive_url = get_post_type_archive_link($post_type);
- if( !empty($archive_url) || $post_type == 'post' ){ //posts do have archives
- $archive_url = trailingslashit($archive_url);
- $archive_url .= $wp_rewrite->using_permalinks() ? date('Y/m/', $post_timestamp):'?m='.date('Ym', $post_timestamp);
- $more_array['url'] = $archive_url;
- }
- $items[] = apply_filters('wpfc_ajax_more', $more_array, $post_date);
- }
- }
- echo json_encode(apply_filters('wpfc_ajax', $items));
- die(); //normally we'd wp_reset_postdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment