So I am looping through some custom post type called reviews on my Controller. Basically I am looping through a custom post type using ‘rand’ so every time I load it shows different reviews every time. Well it does work but ONLY when I am logged in into Wordpress, but when I act like any other user (logged out) it stays the same.
So far this is what I have in Controller:
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;
}