Get Category of a Custom Post Type
To get categories of a custom post type and display them along with their respective posts, I will use the the_terms() function inside the loop.
the_terms() function display all the associated categories of a custom post type. It requires two parameters, post_id and taxonomy slug.