Home › Forums › WTI Like Post PRO › Get my most liked posts?
Tagged: meta_key, meta_query, query_posts, WP_Query
- This topic has 3 replies, 2 voices, and was last updated 9 years, 11 months ago by Webtechideas.
-
AuthorPosts
-
October 27, 2014 at 6:56 am #235CorbinParticipant
Hello there,
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 time
October 27, 2014 at 8:17 pm #236WebtechideasKeymasterThere 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
October 28, 2014 at 12:48 am #237CorbinParticipantFor 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.
- This reply was modified 9 years, 11 months ago by Corbin. Reason: forgot to add something
- This reply was modified 9 years, 6 months ago by Webtechideas.
November 9, 2014 at 3:58 pm #239WebtechideasKeymasterApology 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.
-
AuthorPosts
- The forum ‘WTI Like Post PRO’ is closed to new topics and replies.