Create Custom Post Type | WordPress Theme Development

Create Custom Post

WordPress theme development is a very important part of the WordPress website. In the development Create Custom Post Type is an essential part. In the first part of my WordPress tutorial series, we learned some plugins. Now we discuss theme and custom theme development. Themes mean front end design layout and functionality for users. Custom fields create custom data to show your website frontend. We learned more advanced concepts like adding custom fields and comment templates. We are done all development without a plugin. Before the theme develops, you need to prepare a theme hierarchy file. Then start your theme development with custom post fields.

What is learned in The Post Series

  • Create a custom post type
  • Add a custom meta box
  • Create custom fields
  • Input text field
  • Textarea fields
  • Checkbox
  • Select menu

Create Custom Post Type Register

We are starting off with a completely empty WordPress theme, Just now we start to create post type. And complete post type is very needed for post articles. Create a function for custom post type register and supports. Then add to action initial post by this function name.

<?php 
           function create_post_your_post() { 
                 register_post_type( 
                   'your_post', array( 'labels' => array( 'name' => __( 'Your Post' ), ),
                   'public' => true,
                   'hierarchical' => true,
                   'has_archive' => true, 
                   'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
                   'taxonomies' => array( 'post_tag', 'category', ) ) );
             register_taxonomy_for_object_type( 'category', 'your_post' );    
            register_taxonomy_for_object_type( 'post_tag', 'your_post' );
  } 
     add_action( 'init', 'create_post_your_post' ); ?>

Follow the code and write into your WordPress theme file directory. This filename is functions.php and run code into functions.php

Display the Custom Post

Now carefully write the register post type code and then need to display post on the frontend page. So for this result, you will write some code to display the posts anywhere on your website. Just an idea writes code for display post. One single post design looping this content and all posts get from a database. Code is written in anywhere like as


<?php 

           $args = array( 'post_type' => 'your_post', ); 

          $your_loop = new WP_Query( $args ); 

        if ( $your_loop->have_posts() ) : while ( $your_loop->have_posts() ) : $your_loop->the_post();                
 $meta = get_post_meta( $post->ID, 'your_fields', true ); ?> 

                             <!-- contents of Your Post --> 

       <?php endwhile; endif; wp_reset_postdata(); ?>

This article only goes the most basic way to custom post type register. When you need to custom post type that is a need for other kinds of posts published. And here you will add any type post of WordPress website.



October 20, 2019

More details about the author from social media.


Join now for FREE!

FREE promote your website, business, product, and earn money by submitting your articles, Wordpress themes, templates & web applications!
[ Conditional ]

Related Tutorials


Wordpress Setup

How To Setup WordPress | Complete Guide Step By Step

ARIF MH : Hello user, now we are starts how to setup WordPress complete guide for a beginner.…

Protect Your Business From Cyber Attacks

Tips To Protect Your Business From Cyber Attacks

TCGNS : Cybersecurity threats have been on the rise over the years. Many companies have become victims…

Freshdesk Pricing & Features

Freshdesk: Pricing & Features

Nimisha Saxena : In today’s world, managing customers is a big task as customer demand patterns have changed.…

WordPress Pagination

How to Create Pagination | WordPress Theme Development

A web art : Hello, user now we write a tutorial about how to create pagination in Wordpress. Theme…