Hello I have code intended to get the most viewed post for last 2 days and it seems like not working or maybe my code is just incorrect. I appreciate any help. Thanks.
$args = array(
'post_type' => 'post',
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'date_query' => array(
array(
'after' => '2 days ago',
)
)
);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul class="posts-list">';
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<li>
<?php if ( has_post_thumbnail() ) : ?>
<a href="https://wordpress.stackexchange.com/questions/232809/<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
<div class="content">
<time datetime="<?php echo get_the_date(DATE_W3C); ?>"><?php the_time('d, F Y') ?></time>
<span class="comments">
<a href="<?php comments_link(); ?>" class="comments"><i class="fa fa-comments-o"></i> <?php echo get_comments_number(); ?></a>
</span>
<a href="https://wordpress.stackexchange.com/questions/232809/<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title();?></a>
</div>
</li>
<?php }
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}