title: Get posts published between specific dates in wordpress
body: <p>I'm working a on a widget that will display posts published between two dates, for example Jan 15 and March 15, but I don't know how do it.</p>
  
  <p>I saw a few solutions that mention query_posts() but I don't think that's a good solution. So I'm open to any suggestions how to do this.</p>
  
  <p>At the moment I'm thinking using pre_get_posts, WP_Query, or get_posts and I tried with this line of code:</p>
  
  <pre><code>function my_home_category( $query ) 
  {
      if ( $query-&gt;is_home() &amp;&amp; $query-&gt;is_main_query() )
      {
          $query-&gt;set( 'day', '15');
      }
  }
  add_action( 'pre_get_posts', 'my_home_category' );
  </code></pre>
  
  <p>But this returns all the posts published on 15th of any month. I know I can set something like:</p>
  
  <pre><code> $query-&gt;set( 'monthnum', '1');
  </code></pre>
  
  <p>and get posts published on 15th January, but I want to get all posts published between 15th Jan - 15th March, and I don't know how to achieve that.</p>
  
  <p>It doesn't have to use pre_get_posts, it could be get_posts or WP_Query, I'm just looking for a simple way to do it.</p>