Created
July 21, 2017 11:00
-
-
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.
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 | |
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