To search for posts based on date, you can set up a quick instance of WP_Query. The best place to look is the official documentation, and in particular the section on the date parameters.
A basic search for posts in a particular month will look a little like this:
<?php
$the_query = new WP_Query( array(
'm' => '201607', // will return posts in July 2016
'posts_per_page' => '10', // lets get only the latest 10 posts
'post_type' => 'post', // you can set this to a different post type if needed
'post_status' => 'publish', // 'published' posts only, not draft/private etc.
) );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
the_title();
the_content();
// whatever else about the post you want to output :)
}
}
wp_reset_postdata(); // restore original post data, since custom queries modify it
?>
As described in the documentation I linked to, you can also use parameters year
and monthnum
, or even return multiple months and years at the same time using a slightly more complicated date_query
(examples are in the documentation).