What is a custom post type?#
WordPress comes with several default content types: posts, pages, media and a few others. When you need a new kind of content with its own fields, you define a custom post type. Each post type gets its own menu in the dashboard.
Example#
Consider a language school. Instead of mixing courses in with posts, it creates a "Course" post type with fields such as duration, teacher and tuition. A separate Courses menu appears in the dashboard, and an archive page for courses is created on the site.
Where is it used?#
- Portfolio and case studies
- Products; WooCommerce itself uses this
- Events, listings, team members and testimonials
How is it created?#
With a function called register_post_type in code, or with plugins that offer a graphical interface. It usually comes together with a custom taxonomy, which is your own version of categories.
Important notes#
- After registering, save the permalinks once
- If you put the code in the theme, the post type disappears when you change themes; it is better to put it in a plugin
Common mistake#
Using ordinary posts for everything. As the site grows, management becomes hard.