Query_post 5 post first / last of post_id

Here I’ve written a function for you. It will return you an array of posts. You need to use is as wpse_243452_get_posts_by_ids( 50, 5, false ) if you need to get next X posts then just pass the second parameter as the integer number how many posts you need and then pass true. If you ned the previous X then change the last parameter to false. Here X is equal to $num.

Here is your function-

function wpse_243452_get_posts_by_ids( $post_id, $num, $next = true ) {
    $ids = [];
    if ( $next ) {
        for ( $i = 0; $i < 5; $i++ ) {
            $ids[] = $post_id;
            $post_id++;
        }
    } else {
        for ( $i = 0; $i < 5; $i++ ) {
            $ids[] = $post_id;
            $post_id--;
        }
    }
    $args = [
        'post__in' => $ids
    ];
    $ids = array_filter($ids, function ($x) use ($num) { return $x < $num; });
    $posts = get_posts($args);
    return $posts;
}

After getting the posts you can run a foreach loop and decorate your posts.