How to create custom post in wordpress

In this article we will see how to create custom post when we develop WP plug-ins
In WordPress you can create different types of post such as

  • Post (Post Type: ‘post’)
  • Page (Post Type: ‘page’)
  • Attachment (Post Type: ‘attachment’)
  • Revision (Post Type: ‘revision’)
  • Navigation Menu (Post Type: ‘nav_menu_item’)
  • Custom CSS (Post Type: ‘custom_css’)
  • Changesets (Post Type: ‘customize_changeset’)

These are the default post types you find in WordPress
Now we will see how to create custom post which you can create

(1) Create folder named custompostexample inside the wp-content>plugin and create index.php file

Now you can go to WordPress Admin and click on the Installed Plugin in the plugin section

Now you can activate the plug-in

(2) Now we can create the custom post
I am going to create to custom post for Book. We have register_post_type() function

Above code will create a custom post type called “BooK”
Now you can see the custom post Book in the admin section of the WordPress

Now you can do Add New , Update and Delete operations for the custom post

The register_post_type() has several arguments. First one is the identifier for the custom post. Second one is the label and it has singular and plural forms. Third argument is public to show the custom post type in administration menu of the WordPress

You can show the custom post in content area of the WP by making public to true

Leave a Reply

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