Viewing 1 replies (of 1 total)
  • Thread Starter sarse92

    (@sarse92)

    Hi, is this code correct to retrieve current day popular posts?
    
    $today = getdate();
    $args = [
    ‘post_type’ => ‘post’, // Assuming you want blog posts. Change if needed.
    ‘posts_per_page’ => 3, // Adjust to the number of posts you want.
    ‘order’ => ‘DESC’, // Order from highest to lowest views.
    ‘post__not_in’ => [ $post->ID ],
    ‘date_query’ => [
    [
    ‘year’ => $today[‘year’],
    ‘month’ => $today[‘mon’],
    ‘day’ => $today[‘mday’],
    ],
    ],
    ‘orderby’ => ‘post_views’,
    ‘views_query’ => [
    ‘year’ => $today[‘year’],
    ‘month’ => $today[‘mon’],
    ‘day’ => $today[‘mday’],
    ],
    ];
Viewing 1 replies (of 1 total)
  • The topic ‘Query to get last 1 week popular posts’ is closed to new replies.