I'm trying to make use of the Date Parameter 'm' which is for the YearMonth. I can't figure out what the query name is or how to use it to search for posts with it.



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:


$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() ) {
        // 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).

  • Thank you so much! I forgot to write the date out as a string and it works now XD – H.Kim Jul 7 '16 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.