WordPress Custom Post Type: how to display related content

I always prefer to avoid the use of a third-party plugin, if it’s possible to acheive the same result with a few lines of code.
Let’s see how to display a loop of related posts inside the single page template of a custom post type.

We are using the wp_get_object_terms function to retrieve posts from the same custom taxonomy.

Then we can start the loop to display related items inside the template page: