Advertisement
Intermediate PHP, WordPress Plugin & Theme Development

What are custom post types and custom fields in WordPress, and how do they let you extend WordPress beyond its default posts and pages to represent other kinds of content?

Short answer

A custom post type lets you define an entirely new kind of content beyond WordPress's default built in posts and pages, such as a dedicated product, event, or testimonial content type, each with its own listing and editing screens within the admin dashboard, while custom fields…

Save PHP mock interview
Advertisement
AModel answer
A custom post type lets you define an entirely new kind of content beyond WordPress's default built in posts and pages, such as a dedicated product, event, or testimonial content type, each with its own listing and editing screens within the admin dashboard, while custom fields let you attach additional, structured pieces of information to any individual piece of content, such as attaching a specific price and stock quantity field to each individual product, giving you the flexibility to model many different kinds of real world content beyond a standard WordPress blog post.
register_post_type('product', [
    'label' => 'Products',
    'public' => true,
    'supports' => ['title', 'editor', 'thumbnail'],
]);
Real-world example
An online store built on WordPress registers a custom product post type, letting a site administrator manage individual products through their own dedicated screens within the admin dashboard, completely separate from the site's regular blog posts.
Likely follow-ups
  • What is the difference between a custom post type and a regular WordPress category or tag?
  • How do you actually query and display a list of a specific custom post type on the front end of a site?
Related topics