Skip to content

Instantly share code, notes, and snippets.

@whatjackhasmade
Created July 21, 2017 11:00
Show Gist options
  • Save whatjackhasmade/2af8bd31fbf107b4ac442036fe3dc430 to your computer and use it in GitHub Desktop.
Save whatjackhasmade/2af8bd31fbf107b4ac442036fe3dc430 to your computer and use it in GitHub Desktop.
Get Posts Published Between Two Dates The loop and the query_posts() WordPress function allow you to easily retrieve a list of posts published in a specific week or month. Unfortunately, getting posts published between, for example, March 17 and May 3 isn’t that easy. Let’s solve this problem.
<?php
function filter_where($where = '') {
$where .= " AND post_date >= '2009-03-17' AND post_date <= '2009-05-03'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
while (have_posts()) :
the_post();
the_content();
endwhile;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment