0

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('-7 days')), //value of "order-date" custom field
        'compare' => '<=', //show post less than or equal to today
        'type' => 'CHAR'
      )));
    
0

@Sadia Please, try this once::

$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('-7 days')), //value of "order-date" custom field
                'compare' => '>=', //show post less than or equal to today
            )
        )
);

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.