Wordpress sort WP ULike posts in custom query?

Viewed 714

I'm trying to implement this WP ULike plugin sort example inside my custom query but no success so far as I'm not a WordPress pro. Any help is appreciated, thanks a lot!

My custom query:

$heroes_query = new WP_Query(
    array(          
        'posts_per_page' => 3,
        'post_type' => 'heroes',
        'order' => 'DESC'
    )
); 

And this is from their documentation:

/**
 * Get most liked posts in query
 *
 * @param integer $numberposts      The number of items
 * @param array|string $post_type   Select post type
 * @param string $method            keep this as default value (post, comment, activity, topic)
 * @param string $period            Date peroid (all|today|yeterday|week|month|year)
 * @param string $status            Log status (like|unlike|dislike|undislike)
 * @return WP_Post[]|int[]          Array of post objects or post IDs.
 */
$wp_query = wp_ulike_get_most_liked_posts( 10, array( 'post' ), 'post', 'all', 'like' );

I also tried something from this example but still not working:

<?php 
        
        $heroes_query = new WP_Query(
        array(  
            $post__in = wp_ulike_get_popular_items_ids(array(
                'type'   => 'post',
                'status' => 'like',
                'period' => 'all'
            )),     
            'posts_per_page' => 3,
            'post__in' => $post__in,
            'post_type' => 'heroes',
            'orderby' => 'post__in',
            'order' => 'DESC'
            )
        ); ?>       
        <?php while ($heroes_query -> have_posts()) : $heroes_query -> the_post(); ?>           
            <div class="col-md-4 col-lg-4">
                <?php get_template_part( 'loop-templates/content-card-hero' ); ?>
            </div><!-- /.col -->    
        <?php 
        endwhile;
        wp_reset_postdata();
        ?>

So what I want is to get the 3 most liked custom post types named "heroes". But this is what I get instead: enter image description here

1 Answers

thanks to your question, I managed to solve my problem. so I want to share with you the solution

$post__in = wp_ulike_get_popular_items_ids(array(
                'rel_type'   => 'heroes',
                'status' => 'like',
                'period' => 'all'
            )),  
Related