Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Forked from LinzardMac/file.php
Created January 27, 2013 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninnypants/4645709 to your computer and use it in GitHub Desktop.
Save ninnypants/4645709 to your computer and use it in GitHub Desktop.
<?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