-
-
Save ninnypants/4645709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function posts_by_day() { | |
global $json_api, $post; | |
$days = array(); | |
add_filter( 'posts_where', array( $this, 'filter_where' ) ); | |
$query = new WP_Query( array( | |
'post_type' => array('post', 'imported_content' ), | |
'posts_per_page' => -1, | |
) ); | |
if( $query->have_posts() ): while( $query->have_posts() ): $query->the_post(); | |
if( !isset( $days[ get_the_time( 'Y-m-d' ) ] ) ) | |
$days[ get_the_time( 'Y-m-d' ) ] = array(); | |
$days[ get_the_time( 'Y-m-d' ) ][] = $post; | |
endwhile; | |
endif; | |
// $days = array_values( $days ); | |
return array( | |
"posts" => $days, | |
); | |
} | |
public function filter_where( $where = '' ) { | |
global $wpdb, $date_range; | |
// posts for March 1 to March 15, 2010 | |
if( isset( $_GET['start_date'] ) && isset( $_GET['end_date'] ) ) | |
$where .= $wpdb->prepare( " AND post_date >= %s AND post_date < %s", $_GET['start_date'], $_GET['end_date'] ); | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment