title: Popular Post with wp_query and date_query wordpress
body: <p>I am trying to create a popular post section on my website to show the top 5 most popular posts of the past week.</p>
  
  <p>Function for Popular Post</p>
  
  <pre><code>function shapeSpace_popular_posts($post_id) {
      $count_key = 'popular_posts';
      $count = get_post_meta($post_id, $count_key, true);
      if ($count &lt; 1) {
          delete_post_meta($post_id, $count_key);
          add_post_meta($post_id, $count_key, '0');
      } else {
          $count++;
          update_post_meta($post_id, $count_key, $count);
      }
  }
  function shapeSpace_track_posts($post_id) {
      if (!is_single()) return;
      if (empty($post_id)) {
          global $post;
          $post_id = $post-&gt;ID;
      }
      shapeSpace_popular_posts($post_id);
  }
  add_action('wp_head', 'shapeSpace_track_posts');
  </code></pre>
  
  <p>Loop for the Popular Post</p>
  
  <pre><code>&lt;?php $popular = new WP_Query(array(
                      'posts_per_page'=&gt;5,
                      'date_query'          =&gt; array(
                          //set date ranges with strings!
                          'after' =&gt; '1 week ago',
                          'before' =&gt; 'today',
                          //allow exact matches to be returned
                          'inclusive'         =&gt; true,
                      ),
                      'meta_key'=&gt;'popular_posts',
                      'orderby'=&gt;'meta_value_num',
                      'order'=&gt;'DESC'));
                      while ($popular-&gt;have_posts()) : $popular-&gt;the_post(); ?&gt;
                      &lt;h5 class="section_category"&gt;
                          &lt;?php the_category(', ') ?&gt;
                      &lt;/h5&gt;
                      &lt;div class="trending_title"&gt;
                          &lt;?php the_title( sprintf( '&lt;h4&gt;&lt;a href="%s" rel="bookmark"&gt;', esc_url( get_permalink() ) ), '&lt;/a&gt;&lt;/h4&gt;' ); ?&gt;
                      &lt;/div&gt;
                      &lt;h5 class="section_author"&gt;
                          By &lt;?php coauthors_posts_links(); ?&gt;
                      &lt;/h5&gt;
                      &lt;div class="border-bottom"&gt;&lt;/div&gt;
                      &lt;?php endwhile; wp_reset_postdata(); ?&gt;
  </code></pre>
  
  <p>If you can help in anyway I would be greatful.</p>
  
  <p>Thank you,</p>