October 27, 2014 at 6:56 am #235
I see you’re using these query post arguments in the most-liked-posts.php template to display the most liked posts:
'meta_key' => '_wti_like_count', 'orderby' => 'meta_value_num'
I’m wondering what I would have to change the $args to to output my most liked posts using WP query. Would it be something like this:
'order_by' => 'meta_value_num', 'post__in' => get_user_option( 'wti_user_liked_posts_code', get_current_user_id() )
I would really appreciate the help in using WP_query to sort my most liked posts.
Thank you for your timeOctober 27, 2014 at 8:17 pm #236
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(); ?>
ThanksOctober 28, 2014 at 12:48 am #237
For some reason that output a link to the current page template I using, “nothing found” and not a loop. Second is that query for the My Most liked posts, or the site wide Most liked posts. I’m looking for how I could get My most liked posts with the WP_Query. Although; knowing how to output site wide most liked posts using WP_Query would be beneficial as well.
Thank you very, very much for your help so far.November 9, 2014 at 3:58 pm #239
Apology for this delayed reply. My Most Liked Posts is not directly possible with WP_Query. You will have to first get the post ids for the user from our table and then pass those ids to the WP_Query to get the desired result.
Not sure whats the issue you are referring with the “nothing found” you have mentioned. Can you please share your site link so that we can have a look at that and suggest a fix.
You must be logged in to reply to this topic.