Home Forums WTI Like Post PRO Get my most liked posts?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #235
    Corbin
    Participant

    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

    #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

    #237
    Corbin
    Participant

    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.

    • This reply was modified 9 years, 8 months ago by Corbin. Reason: forgot to add something
    • This reply was modified 9 years, 4 months ago by Webtechideas.
    #239
    Webtechideas
    Keymaster

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘WTI Like Post PRO’ is closed to new topics and replies.