Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Feature image in related post

$
0
0

Replies: 0

Hi All,

I am using some code in my function.php to return related post in JSON API.

/**
* Related Post in API
*/

function related_posts_endpoint( $request_data ) {

    $post_id = $request_data['post_id'];

    $uposts = get_posts(
        array(
            'post_type' => 'post',
            'category__in'   => wp_get_post_categories($post_id),
            'posts_per_page' => 5,
            'post__not_in'   => array($post_id),
        )
    );

    return  $uposts;
}

add_action( 'rest_api_init', function () {

    register_rest_route( 'sections/v1', '/post/related/(?P<post_id>[\d]+)', array(
            'methods' => 'GET',
            'callback' => 'related_posts_endpoint'
    ));

});

That response from that API is not returning any thumbnail of the post. What if I need to add post thumbnail in that API responses?

Thanks


Viewing all articles
Browse latest Browse all 59525

Trending Articles