如何使Word Press Custom Post随机显示而无需登录?当我没有登录时它不会改变

问题描述

您如何在无需登录的情况下随机显示Word Press自定义帖子?当我未登录时,它不会改变。到目前为止,这就是我所拥有的

 public function reviews()
{
    $args =[
        'post_per_page' => -1,'offset' => 0,'orderby' => 'rand','order' => 'ASC','posts_per_page' => '4','post_type' => 'reviews'
    ];

    $the_query = new \WP_Query($args);
    $reviews = [];
    if($the_query->post_count > 0)
    {
        $reviews = array_map(function ($reviews){
            $post = get_post($reviews);
            $name = get_the_title($reviews);
            $content = $post -> post_content;
            return (object)[
                'name' => $name,'content' => $content
            ];

        },$the_query->posts);

        wp_reset_postdata();
    }
    return $reviews;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)