When rendering any web page, the default WordPress functionality is to search the current theme directory for an applicable template suitable for the content at hand. In the case of a single custom post type item, such as a Book Review, it first looks for a single item template named single-<post-type-name>.php, where the latter part is the actual post type name. If it does not find this file, it defaults to the general single item template. In the first recipe of this chapter, the template that was used to show the Book Review was the default single item template, simply named single.php.
To add better support for our new post type, this recipe associates a function with the template_include filter hook to change that behavior. More specifically, we use the locate_template function to check whether the user provided a template for the book_reviews post type in the theme directory. If no template is found, we register a filter to overwrite the page contents with our own layout. This gives users the flexibility to use our predefined layout or to provide their own.
The rest of the recipe implements our fallback filter function for Book Review content. This code makes use of many WordPress template functions, such as get_the_ID() and get_the_content(), as well as the get_post_meta function, to display various elements of the current item, including the book author and its rating, as well as the main post content and the featured image.
To help users build their own theme template for your custom post type, you should provide code snippets in your plugin documentation, showing how to retrieve your custom post type's custom fields.