Menu

What You Need to Know About Custom Post Types and Custom Fields

Custom Post Types and custom fields are advanced WordPress features. Many site owners have Custom Post Types and custom fields added by a plugin or theme, and use these, without needing to understand the mechanics. They just work. However, site builders who want to use WordPress for something other than a static brochure site or add functionality beyond being a blogging platform will need to understand these advanced features. In this article I'm going to tell you what you need to know so that you can make intelligent choices while building your sites.

What are Post Types

WordPress has the concept of "post types." Posts and Pages are two notable examples of post types. They have a lot of similarities. A Post and a Page both have a title, content, featured image, an author, published date, the option for comments, and privacy settings. The title, content area, featured image, author, and date are data fields attached to these post types. There are some differences, however, between Posts and Pages. Posts have categories and tags, they have automatically created archive lists of Posts, and Posts show up in the site's RSS feed. Pages don't have categories, tags, and archives. Instead, Pages have the option to be ordered hierarchically.

What are Custom Post Types

Posts and Pages are post types that are built into WordPress core. Custom Post Types are not part of WordPress by default, but are added using PHP code in either the theme or a plugin. A Custom Post Type may have the same fields as Posts or Pages, or they may omit some of those default fields. Usually, though, Custom Post Types add additional fields. Fields added in addition to the built in WordPress fields are called "custom fields."

A Book Review Custom Post Type, for instance, may have the same title, author, content area, publication date and featured image that a Post does, but it may also have additional custom fields, such as the ISBN, illustrator, publisher, link to the book author's website, book publication date, reviewer's name, and review rating. The need for additional custom fields that you want to handle and display differently is one common reason for adding a Custom Post Type. Note that it is possible to add custom fields to Posts and Pages, and sometimes that works. However, if you wanted to have a blog and a book review section on the site, for instance, then it is easier to organize and manage if you add a Custom Post Type. For example, you can show the Book Review fields using a different layout than the blog Posts.

About Categories, Tags, and Custom Taxonomies

Posts have Categories and Tags built in. The difference between the two is that Categories can be hierarchical while Tags are "flat." You use these to group together your Posts. Custom Taxonomies are the same as Categories and Tags, but they are ones you add yourself. You can define them to be either hierarchical or flat. Sometimes you can use Categories instead of a Custom Post Type. Say For example say you want to write about your vacation and your favorite TV shows. You could create a Custom Post Type for each, but if the fields would be the same, you could assign one a category of "travel" and the other "entertainment." Remember that Categories automatically have listings, called archives, so you would automatically have one listing for "entertainment" and one for "travel" and so may not need a Custom Post Type to separate and organize them. Asking the question, "can I do this with Categories?" is one question you can ask to see if a Custom Post Type is needed.

A Note About Custom Fields

WordPress has the ability to add custom fields to a post type. However, these are simple text fields. Often when site builders use custom fields it is beneficial to use fields that are of a certain type. Continuing with the Book Review example, a URL field for the link to the book author's website, a date field for the book publication date, a number field for the number of rating stars. You can enter a URL, a date, and a number into a text field, but having fields of different types means that you can make sure that a value entered is formatted correctly and is in fact a valid URL, date, or number. This makes it easier for the person entering the information in the editor and it makes it easier to use the information when creating the template or page to display it. There are several plugins that provide more advance custom field options: Advanced Custom Fields free, Advanced Custom Fields Pro, Meta Box, Pods, and Toolset are the most popular options.

The Missing Piece in WordPress Core

So you've determined you need a Custom Post Type, and WordPress core supports them, but guess what? WordPress doesn't provide an interface to create them, neither does it output the custom field data on the frontend. You need a tool to create the Custom Post Types and custom taxonomies. Crocoblock, CPT-UI, Meta Box, Pods, and Toolbox provide a user interface for creating Custom Post Types and custom taxonomies.

Creating Templates for Custom Post Types

Historically the way to output your custom fields is to create a theme template file in PHP. While this is still an option for those who like to code, many advanced builders provide this functionality. This is often referred to as a "theme builder" or theming with the page builder, because it produces the same type of frontend result that you get with hand coded PHP templates. There are a large number of plugins, themes, and builders that have this feature. Take a look at the Dynamic Toolbox on the home page and filter for "Create Templates" for a complete list.

Conclusion - Custom Post Types and Custom Fields

Custom Post Types and custom fields are an advanced topic for site builders. The use of these features helps to structure data input when creating content and to present information to visitors in an organized and coherent fashion on the frontend. There are a number of tools, both free and premium, for creating Custom Post Types and custom fields and for displaying them. The WP Dynamic Toolbox site is dedicated to making information about these topics and tools available for site builders. I hope you've found this article helpful.

Leave a Reply

Your email address will not be published.

>