Create Custom Post Types in WordPress without using Plugin

wordpress custom post types

If you are a wordpress developer then you must need to read this article. In this article i will tell you how to create custom post type in wordpress without using plugin . As you know wordpress has different post types and a single page of content is called a post. Also every post is a specific post type like post, page, attachment etc. All the posts content are stored in same database table named (“wp_posts” ) and post content is differentiated by table column called “post_type”.

By default , after installation of wordpress you will get different post types which is listed below:

  • 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’)
  • User Data Request (Post Type: ‘user_request’ )

Now if you want to create custom post type in wordpress without using plugin then it is very easy and you don’t need to use any plugin. We can create a custom post type in wordpress using register_post_type() function. This custom post type will have its own category and custom field.

In this article we will create a custom post type : ‘job_listing’. This custom post type will help you to add job listing content in wordpress. For example: if your website offer some job opening content to your users and you want to separate the job listing section from the posts or page section. In that case, you would probably need a separate job listing post type. This custom post type will have its own custom category and custom fields.

Create Custom Post Type

At the time of adding a post type, you always need to register taxonomies of that post type. You can define and register a taxonomy using register_taxonomy() function. The register_post_type() function is used to create a post type and it only be called through the init action hook.

You only need to open and modify functions.php file which is located in /wp-content/themes/theme_name/functions.php. So open the functions.php file and copy and paste following code:

You can see register_post_type() function accepts two parameters, $post_type and $args.

  • $post_type – Specify your custom post type.
  • $args – An array of the arguments.

You can see register_taxonomy() function accepts three parameters, $taxonomy$object_type, and $args.

  • $taxonomy – The Name of the taxonomy.
  • $object_type – The name of the object type for the taxonomy object.
  • $args – An array of the arguments.

register_post_type and register_taxonomy both function accept the arguments in $args parameter. you can check following link for arguments more details:

https://codex.wordpress.org/Function_Reference/register_post_type

After inserting above example code in function.php file, you can see the Job Listing menu appears on the left side menu in WordPress admin panel. This custom post type menu allows you to view, add, edit, delete separate contents for the custom post type and manage custom post type categories.

SEE:How to Show Related Posts for Custom Post Type in WordPress

Related posts