Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress是否在自定义查询中对类似帖子进行排序?_Php_Wordpress - Fatal编程技术网

Php Wordpress是否在自定义查询中对类似帖子进行排序?

Php Wordpress是否在自定义查询中对类似帖子进行排序?,php,wordpress,Php,Wordpress,我正试图在我的自定义查询中实现这个WP-ULike插件,但没有成功,因为我不是WordPress专业人士。非常感谢您的帮助,非常感谢 我的自定义查询: $heroes_query = new WP_Query( array( 'posts_per_page' => 3, 'post_type' => 'heroes', 'order' => 'DESC' ) ); 这是他们的文件: /**

我正试图在我的自定义查询中实现这个WP-ULike插件,但没有成功,因为我不是WordPress专业人士。非常感谢您的帮助,非常感谢

我的自定义查询:

$heroes_query = new WP_Query(
    array(          
        'posts_per_page' => 3,
        'post_type' => 'heroes',
        'order' => 'DESC'
    )
); 
这是他们的文件:

/**
 * 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' );
我也尝试了一些,但仍然不起作用:

<?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();
        ?>

因此,我想得到的是3个最受欢迎的自定义帖子类型命名为“英雄”。但我得到的却是:
多亏了你的问题,我终于解决了我的问题。所以我想和大家分享解决方案

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

只有代码的答案没有特别的帮助。请添加一些关于此代码如何解决问题的描述。作者有一个拼写错误键入'=>'post',此函数wp\u ulike\u get\u popular\u items\u ids()接受参数'rel\u type'=>'post\u type',其中post\u type,您的wordpres post type,作者的是'heroes'