Home › Forums › WTI Like Post PRO › Get my most liked posts? › Reply To: Get my most liked posts?
October 27, 2014 at 8:17 pm
#236
Webtechideas
Keymaster
There will be no changes in the $args, only changes are with the loop and and reset. Please find the code below.
<?php
// Get the last voted time based on a week
$last_voted_time = GetWtiLastDate('7');
// Query to get all posts sorted by like count after a specific date
$the_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => 5,
'meta_key' => '_wti_like_count',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => '_wti_last_voted_time',
'value' => $last_voted_time,
'type' => 'DATETIME',
'compare' => '>='
)
)
)
);
if ( $the_query->have_posts() ) :
?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<article>
<header class="entry-header">
<h1 class="entry-title"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h1>
</header>
<div class="entry-content"><?php the_content(); ?></div>
</article>
<?php endwhile; ?>
<?php
else :
?>
<article>
<header class="entry-header">
<h1 class="entry-title"><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h1>
</header>
<div class="entry-content"><?php _e( 'Nothing Found', 'wti-like-post' ); ?></div>
</article>
<?php
endif;
/* Restore original Post Data */
wp_reset_postdata();
?>
Thanks