Custom Post Types in WordPress

What Are Custom Post Types?

While most WordPress sites at CSU primarily use Pages, Posts can be just as, if not more, useful in the right context. Typically, posts are viewed as a blogging feature intended for your everyday, typical blog. However, nothing within WordPress restricts you to use posts solely forĀ blog posts. You can create your own custom post type (CPT) to do much more.

When and Why Would I Want to Use Them?

Any time you have content that is structured and repetitive, CPTs could be a good idea. Take, for example, your staff members. When you display your staff members on your website, odds are they’ll all have some of the following information displayed:

  • Name
  • Job title
  • Email address
  • Phone number
  • Picture
  • Bio

Instead of managing all of that content within one large page, why not pull that data out of the page and create a custom post type to manage staff members and their information? Each staff member would be their own post. With this approach, anytime you need to make edits to a staff member, you can simply go to, say, the “Staff Members” section of the WordPress dashboard and easily manage all staff members and their information there.

How To Create a Custom Post Type

Rather than rewriting what has already been extremely well documented, I’ll instead provide a link to a well-written post from wpbeginner.com.

Custom Post Types in Action

Now that you have your post type setup, you’ll want a way to display all of this information on the page. The easiest way to retrieve your “posts,” is to use a grid element/widget provided by your page builder. Such tools will loop through each post and display the information how you specify.

Below is a series of screenshots that demonstrate a basic use-case of a custom post type.

Further Reading

Taking CPTs to the Next Level with Custom Fields

Custom post types become more powerful when you combine them with custom fields (article coming soon). By default, the fields you can use in a post are:

  1. Title
  2. Body content
  3. Featured image

But what if you want to have a structured way to store pieces information without clumping it all together inside the body content? That’s where custom fields come into play. If you’d like to see an example of custom post types with custom fields, you can look at the Recognized Chapters section of Fraternity and Sorority Life’s website. Each card on that page, as well as all of the data on each chapter’s page, is maintained with custom fields.

Posts Are at the Heart of WordPress

While we tend to focus on WordPress pages, did you know that they are actually a custom post type themselves? If you ever look into the WordPress code-base, you’ll quickly realize that even what we see referred to as “pages” are, in fact, nothing more than type of post.

In fact, many of your plugins heavily utilize custom posts. Take Gravity Forms for example. Each form you create is actually a custom post type!