How to determine next custom post in hierarchy

Here I’ve written a SQL based function for you-

function the_dramatist_get_last_post($current_post_type="viz", $other_post_type="portfolio", $post_id = '', $prev = true) {
    global $wpdb;
    $order_by = $prev ? 'ASC' : 'DESC';
    $sign = $prev ? '<' : '>';
    $sql = $wpdb->prepare("SELECT * FROM {$wpdb->posts} AS p
                            WHERE p.post_type != %s
                            AND p.post_type LIKE %s
                            AND p.id {$sign} %d
                            ORDER BY id {$order_by}
                            LIMIT 1",
            array(
                $current_post_type,
                $other_post_type,
                $post_id
            )
    );

    return $wpdb->get_results($sql);
}

Use it like the_dramatist_get_last_post('viz', 'portfolio', 559, false). It’ll give you both previous and next post based on the last parameter $prev. If $prev is true then it’ll give you previous and if false then it’ll give you the next post. Rest of the parameters uses is too simple. Hope you’ll understand those easily.