On WP_Query I am trying to figure out how to code correctly to show the past 45 days of Posts from categories 7,8,12,34. I am trying to use "posts_where" too but I can not figure out the syntax. Here is what I am incorrectly doing:
<ul>
<?php
$recentPosts = new WP_Query();
$recentPosts->query('cat=7,8,12,34');
while ($recentPosts->have_posts()) :
$recentPosts->the_post();
function filter_where( $where = '' ) {
// posts in the last 45 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-45 days')) . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $query_string );
remove_filter( 'posts_where', 'filter_where' );
?>
<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>