Support » Plugin: WP ULike » Sort Most Liked Post issue

  • Resolved faizfizy



    First of all, thanks for the great plugin! I have tried a lot of Like plugin out there but nothing can beats WP ULike.

    I tried to sort posts according to Likes on my archive page. But when I add this line of code $wp_query = wp_ulike_get_most_liked_posts( 10, array( 'post' ), 'post', 'all', 'like' );, it cause an error because the $wp_query returns an array of WP_Posts instead of WP_Query object. Is there any way that I can return this in form of WP_Query object instead?

    Also, this function will not return posts with 0 Likes. Can you advice me how to include this too? If it is too much, I appreciate if you can point me to the right direction to achieve this.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Alimir


    Dear @faizfizy

    You can use the following function to get a list of top posts:

    $post__in = wp_ulike_get_popular_items_ids(array(
    	'type'   => 'post',
    	'status' => 'like',
    	'period' => 'all'

    Then use the post_in parameter to create a query:

    $args['post__in'] = $post__in;
    $args['orderby'] = 'post__in';

    In a recent update, we added the is_normal parameter to this function. You can set the value to true and get unpopular content:
    wp_ulike_get_most_liked_posts( $numberposts = 10, $post_type = '', $method = '', $period = 'all', $status = 'like', $is_noraml = false )

    Dear @alimir

    Thanks for the reply! Your tip guide me to the right direction.

    I am now able to return WP_Query object for Most Liked Post.

    But I’m unable to get the new parameter is_normal to works. I’m not sure what is the supposed intended behaviour, however I manage to return posts with 0 like with post__not_in argument and merge the 2 WP_Query object together.

    Also just to point out, in case you didn’t notice, there is a typo for is_normal variable.

    Thanks for your time. Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.