Post Types

Post Types

internally, all of the Post Types are stored in the same place — in the wp_posts database table — but are differentiated by a database column called post_type.
In addition to the default Post Types, you can also create Custom Post Types.

Default Post Types Default Post Types

There are five default Post Types readily available to users or internally used by the WordPress installation:
  • Post (Post Type: ‘post’)
  • Page (Post Type: ‘page’)
  • Attachment (Post Type: ‘attachment’)
  • Revision (Post Type: ‘revision’)
  • Navigation menu (Post Type: ‘nav_menu_item’)
The Post Types above can be modified and removed by a plugin or theme, but it’s not recommended that you remove built-in functionality for a widely-distributed theme or plugin.
The most common post types you will interact with as a Theme Developer are Post, Page, Attachment, and Custom Post Types.

Post Post

Posts are used in blogs. They are:
  • displayed in reverse sequential order by time, with the newest post first
  • have a date and time stamp
  • may have the default taxonomies of categories and tags applied
  • are used for creating feeds
The template files that display the Post post type are:
  • single.php and single-post.php
  • category.php and all its iterations
  • tag.php and all its iterations
  • taxonomy.php and all its iterations
  • archive.php and all its iterations
  • author.php and all its iterations
  • date.php and all its iterations
  • search.php
  • home.php
  • index.php
Additionally, theme developers can display Post post types in front-page.php if they so desire.

Page Page

Pages are a static Post Type, outside of the normal blog stream/feed. Their features are:
  • non-time dependent and without a time stamp
  • are not organized using the categories and/or tags taxonomies
  • can have page templates applied to them
  • can be organized in a hierarchical structure — i.e. pages can be parents/children of other pages
The template files that display the Page post type are:
  • page.php and all its iterations
  • $custom.php and all its iterations
  • front-page.php
  • search.php
  • index.php

Attachment Attachment

Attachments are commonly used to display images or media in content, and may also be used to link to relevant files. Their features are:
  • contain information (such as name or description) about files uploaded through the media upload system
  • for images, this includes metadata information stored in the wp_postmeta table (including size, thumbnails, location, etc)
The template files that display the Attachment post type are:
  • MIME_type.php
  • attachment.php
  • single-attachment.php
  • single.php
  • index.php

Custom Post Types Custom Post Types

Using Custom Post Types, you can create your own post type. It is not recommend that you place this functionality in your theme. This type of functionality should be placed/created in a plugin. This ensures the portability of your user’s content, and that if the theme is changed the content stored in the Custom Post Types won’t disappear.
While you generally won’t develop Custom Post Types in your theme, you may want to code ways to display Custom Post Types that were created by a plugin.  The following templates can display Custom post types:
  • single-{post-type}.php
  • archive-{post-type}.php
  • search.php
  • index.php
Additionally, Theme Developers can display Custom Post Types in any template file, often by using multiple loops.

Comments