I have a custom WP_Query loop that I use for the main archive page. How can I filter the custom query to diplay posts from within 2 days +/- of one year ago from todays date?
My current query:
$posts_args = array(
'post_type' => 'album',
'post_status' => 'published',
'paged' => $paged,
'order' => strtoupper($album_sort),
'orderby' => 'date'
);
I know that the codex lists this time parameter for WP_Query but I've never used a loop filter and am a little confused on the implementation.
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
// posts 30 to 60 days old
$where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
Any assistance is appreciated.