Home / Blog / How to Create Custom Post Types in WordPress

How to Create WordPress Custom Post Types

How to Create Custom Post Types in WordPress

There are several different types of content in WordPress, and they are categorized into post types. A post is a single object, but it’s also the name of a regular post type called posts. WordPress comes with a variety of different post types by default, all of which are contained in the database under the wp posts table. For a few years, WordPress has been gaining popularity as a general CMS, but the custom post type mechanism, which allows the development of a large range of content, was the true game-changer. Let’s take a look at how this came to be and all of the possibilities that this fantastic feature has.

Now, let’s look at what WordPress can do for you

A custom post type is just a generic post with a database post type attribute that is distinct. Regular posts are of the “post” post type, while pages are of the “page” post type, and attachments are of the “attachment” post type, and so on. You can now make your own to show the type of content you’ve made. For novels, movies, ratings, and items, for example, you can make custom post types.

With only a few lines of code, you will obtain the following results:

  • The custom post type will appear as a separate menu item in the backend, with its own post list and “add new” page.
  • The archive page for the post type can be found by going to http://example.com/customposttype/. This is equivalent to searching on the front page for the most recent posts with the “post” post type.
  • You may make categories and tags accessible to the custom post type, or build custom taxonomies.

Default Custom Post Types

Unless removed, the following post types are always included in a WordPress installation:

  • Posts
  • Pages
  • Attachments
  • Revisions
  • Navigation Menus
  • Custom CSS
  • Changesets
How to Create Custom Post Types in WordPress? Ideally you should create a plugin when working with custom post types, but if you don’t know how, or just need a quick test, you can use the functions.php file in your theme.

Creating Custom Post Types

The first thing on our to-do list is to build the post type itself. When dealing with custom post types, it’s better to build a plugin, but if you don’t know how or only need a short test, you can use your theme’s functions.php file.

It will build a post type with absolutely no customization at its most basic shape. It won’t be visible to the public, won’t be in the admin, and contact notifications will be the same as for posts (“post saved,” “post updated,” etc.). We’ll  go over some of the most commonly-used alternatives and add them to the previously empty $args list to tailor our current post type to our needs.

  • labels This can be an array that defines the various labels a custom post type may have. I broke this out earlier to make the case for registering a post type more transparent.
  • description A quick overview of our custom post type, including what it does and why we use it.
  • public This choice manages a number of items at once. If you set this to true, plenty of other possibilities would also be true. It is possible, for example, to make a custom post type available but not queryable.

Once you’ve done that, the custom post type should appear in the menu. You should be able to create new posts, browse the post list in the admin, and visit the website’s existing posts.

Was this article helpful?
Yes No
you might like

All you need to know about the Legacy Widget block in WordPress

The Legacy Widget block enables users to add, and preview third-party widgets registered by plugins as well as widgets created using the good old Widgets Editor.

read more
All you need to know about the Legacy Widget block in WordPress

Leave a comment

Your email address will not be published. Required fields are marked *




you might like

How to Create Custom Post Types in WordPress

A custom post type is just a generic post with a database post type attribute that is distinct.

read more
Projects Engine

Sometimes it's better to leave something alone, to pause, and that's very true of programming.

- Joyce Wheeler