Query custom meta value – post view and date meta

I am making my first post view counter. I have stored views in post-view meta and latest date meta post_view_last. Now I want to show posts from say last 7 days, last 30 days. My query for last 7 days is below but it’s not displaying posts. Basic principle-

  1. Query post last 7 days post_view_last
  2. Order post based on post views post-view

    $args = array(
    'post_type' => 'post',
    'posts_per_page' => '3',
    'post_status'  =>  'publish',
    'meta_key' => 'post_view',// say 200
    'orderby' => 'meta_value_num',
    'order' => 'DSC',
    'meta_query' => array(
    'relation'  =>   'AND',
       array(
        'key' => 'post_view_last',//2017-04-14
        'value' => date('Y-m-d', strtotime('-1 week')), //value of "order-date" custom field
        'compare' => '<=', //show post less than or equal to today
        'type' => 'CHAR'
      )));
    

Read more here: Query custom meta value – post view and date meta

Leave a Reply

Your email address will not be published. Required fields are marked *