WordPress houses lots of different types of content and they are divided into something called Post Types. A single item is called a post however this is also the name of a standard post type called posts. By default WordPress comes with a few different post types which are all stored in the database under the wp_posts table.
Default Post Types Default Post Types
The default post types that are always included within a WordPress installation unless otherwise removed are:
- Navigation Menus
- Custom CSS
A post in WordPress is a post type that is typical for, and most used by blogs. Posts are normally displayed in a blog in reverse sequential order by time (newest posts first). Posts are also used for creating RSS feeds.
A page is similar to posts however they have some very important differences. Pages aren't displayed in a reversed time-based order. They can also be placed into a hierarchical order where a page can be the parent or child of another page creating a page structure. Traditionally, pages also do not make use of categories and tags like posts do.
Revisions are a particularly special post type as they are used to create a history of other post types in case you make a mistake and want to rollback to a previous version. Whilst you technically can't edit revisions directly unless you restore a revision, they are editable just like posts and are stored in the wp_posts table like any other post type.
Attachments are another post type that is special as these hold information about any media that is uploaded to your WordPress website. Not only is the main post information stored where other posts are, attachments also make use of the wp_postmeta table for storing extra information like metadata for images and videos that you've added.
Menus in WordPress are lists of links that can be used to navigate your website. This allows you to create custom lists of links to various locations on your website that is used by your visitors and are edited in the theme section of the dashboard away from traditional post types like posts or pages.
Custom CSS Custom CSS
Custom CSS is a theme specific post type used to store CSS saved from The Customizers Additional CSS screen. Each theme can have its own custom CSS post but only the active themes `custom_css` post is actually used.
Changesets are similar to revisions but specifically for the Customizer. This is to keep the Customizer in a persistent state. WordPress will attempt to keep content changes made through the Customizer during the user session in a `customize_changeset` post and attempt to restore them should you exit your current session.
Custom Post Types Custom Post Types
Whilst there are already lots of standard post types within WordPress, you may want to extend the amount of post types you have if you want to break things down into smaller categories. For example, if you want to have a section on Books, it would be better suited to creating a custom post type for them. This can be done using the register_post_type function.
It's highly recommended that you define custom post types within a plugin or must-use plugin to ensure that if you switch themes, the post type isn't lost. That way you can ensure your content is always accessible.
Template Files Template Files
By default WordPress makes use of the index.php, single.php and archive.php files in a theme to display posts of any type of the front-end of a website. However, if you've made a custom post type, you may find that you want to show this information in a different way to other types. You can do this by using post type specific custom templates within your theme.
If you create a post type called Books like in the example above, you can create a template file called single-book.php which will show the individual book posts that you publish. Again, to show all your books in a custom archive page (where they are all listed), you can create an archive-book.php template file and this will show all the book posts that you've published.
Post Type Queries Post Type Queries
In the event that you want to get a list of your custom posts called Books, you can create a new WP_Query instance and fetch them all. This is handy if you want to create a custom loop somewhere on your website and show them in a different way to other posts.
The Posts Query The Posts Query
You might find that in some cases you want to include custom posts into your main query of blog posts. You can do this by using the pre_get_posts filter hook which lets you customize the query that gets your posts before it's shown on the front-end of the website.