Trying to display the content from a custom post type from a page post type

So this is what i have on the controller side.

     $args =[
        'post_per_page' => -1,
        'offset' => 0,
        'orderby' => 'date',
        'order' => 'ASC',
        'post_type' => 'reviews'
    ];

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

        }, $the_query->posts);

        wp_reset_postdata();
    }
    return $reviews;

and this is on view

        @foreach($reviews as $review)
      <blockquote class="blockquote">
        <p class="mb-0">{{$review -> content}}</p>
        <footer class="blockquote-footer"><cite title="Source Title">{{$review -> name}}</cite></footer>
      </blockquote>
    @endforeach

The problem is that instead of showing the content from the review post type it shows the content from the page post type.

any idea on what I am doing wrong?

You’re calling get_the_content() incorrectly. The first argument it takes is not a post, so it’s falling back to the global post–which in this context is your page. I’d recommend reading the documentation for that function: https://developer.wordpress.org/reference/functions/get_the_content/

This topic was automatically closed after 42 days. New replies are no longer allowed.