Whenever a user updates, previews, or does anything with a book, you'll want them to see an accurate message. All we need to do is create an array of messages and then hook them to WordPress, as shown in the following code:
function book_updated_messages( $messages ) { $messages['book'] = array( '', /* Unused. Messages start at index 1. */ sprintf('Book updated. <a href="%s">View book</a>', esc_url(get_permalink($post_ID))), 'Custom field updated.', 'Custom field deleted.', 'Book updated.', (isset($_GET['revision']) ? sprintf('Book restored to revision from %s', wp_post_revision_title((int)$_GET['revision'], false)) : false), print('Book published. <a href="%s">View book</a>', esc_url(get_permalink($post_ID))), 'Book saved.', sprintf('Book submitted. <a target="_blank" href="%s"> Preview book</a>', esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), sprintf('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>', date_i18n('M j, Y @ G:i', strtotime($post- >post_date)), esc_url(get_permalink($post_ID))), sprintf('Book draft updated. <a target="_blank" href="%s"> Preview book</a>', esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))) ); return $messages; } add_filter('post_updated_messages', 'book_updated_messages');
This code creates a function named book_updated_messages(), which sets up an array of messages and returns it. We call this using the filter for post_updated_messages.
Now, our custom post type is ready to use! Go to your wp-admin panel and reload it. You'll see that a new menu has appeared under Comments. It's called Books. Let's add a book, as shown in the following screenshot:
Note that I gave it a custom field named book_author, and I also uploaded a featured image for the book cover. Now, when you go to the main Books page, you'll see the book listed. If you click on the View link under the book's title, you'll see the book displayed using the single.php theme template, which won't be the most reader-friendly experience. Therefore, let's make some new template files to display our books.