Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  WordPress FAQ  >  How to create Custom Post Type or Custom Entries in WordPress
Top Scroll

How to create Custom Post Type or Custom Entries in WordPress

 4 min

The Custom Post Type is basically a customized entry in WordPress, and this is a very useful feature for those who need to customize their website most of the time. By default, WordPress does not allow this types of customization in the entries, forcing us to use plugins or touch the code to create them and display them.

Although there are plugins that can solve the problem but it is always good to know what they do, if at some point we have to touch the code. So let’s see how to manually create the Custom Post Type in WordPress. An advanced step in customizing our website created with popular content management, as we advance in the article on static pages. However, in this tutorial, we also listed some of the WordPress plugins that allow us to customize the entries without getting into programming.

If we want to create a custom entry, we have to go to functions.php file of our WordPress theme where we add the following code.

As an example, let’s make an example of own entry called Journals:

// function will not be used before the 'init'.

add_action ( 'init', 'my_custom_init');

my_custom_init function () {

$ Labels = array (

('General post type name' 'Journals') 'name' => _x,

'Singular_name' => _x ('Journal', 'post type singular name'),

'Add_new' => _x ('Add new' 'Journal'),

'Add_new_item' => __ ('Add New Journal'),

'Edit_item' => __ ('Edit Journal'),

'New_item' => __ ('New Journal'),

'View_item' => __ ('See Journal'),

'Search_items' => __ ('Search Journals'),

'Not_found' => __ ('No Journal found'),

'Not_found_in_trash' => __ ('No Journal found in the trash'),

'Parent_item_colon' => ''

);



// create an array to $ args

$ Args = array ( 'labels' => $ labels,

'Public' => true,

'Publicly_queryable' => true,

'Show_ui' => true,

'Query_var' => true,

'Rewrite' => true,

'Capability_type' => 'post',

'Hierarchical' => false,

'Menu_position' => null,

'Supports' => array ('title', 'editor', 'author', 'thumbnail', 'excerpt' 'comments')

);



register_post_type ('Journal', $ args);

}

This code is not too complicated and only need to change the text to display in the way that interests us.

With this, we will be creating a custom entry and that is already present on our desktop.

Ratings

If you look at the post we see that we have no taxonomy for journals. That is, we have no classification: No genres or authors.

To create taxonomies, we will need the following code:

// the init hooked in action and call the create_journal_taxonomies () function when starting

add_action ( 'init', 'create_journal_taxonomies', 0);

// we created two taxonomies, genre and author for the custom post type "journal"

create_journal_taxonomies function () {

// we add new taxonomy and do hierarchical (as the default categories)

$ Labels = array (

'Name' => _x ('Genres', 'General taxonomy name'),

'Singular_name' => _x ('Genre', 'taxonomy singular name'),

'Search_items' => __ ('Search Genre'),

'All_items' => __ ('All Genders'),

'Parent_item' => __ ('Gender father'),

'Parent_item_colon' => __ ('Gender father'),

'Edit_item' => __ ('Edit Gender'),

'Update_item' => __ ('Update Gender'),

'Add_new_item' => __ ('Add new Gender'),

'New_item_name' => __ ('name new Gender'),

);

register_taxonomy ( 'genre', array ( 'journal'), array (

'Hierarchical' => true,

'Labels' => $ labels, / * this is where the labels $ variable are we created above using * /

'Show_ui' => true,

'Query_var' => true,

'Rewrite' => array ('slug' => 'gender'),

));

// I add another taxonomy, this time it is not hierarchical, as tags.

$ Labels = array (

'Name' => _x ('Writers', 'General taxonomy name'),

'Singular_name' => _x ('writer', 'taxonomy singular name'),

'Search_items' => __ ('Search Writers'),

'Popular_items' => __ ('Popular writers'),

'All_items' => __ ('All writers'),

'Parent_item' => null,

'Parent_item_colon' => null,

'Edit_item' => __ ('Edit Writer'),

'Update_item' => __ ('Update Writer'),

'Add_new_item' => __ ('Add new writer'),

'New_item_name' => __ ('Name of the new writer'),

'Separate_items_with_commas' => __ ('Comma Separate Writers'),

'Add_or_remove_items' => __ ('Add or remove Writers'),

'Choose_from_most_used' => __ ('Choosing among the most used Writers')

);

register_taxonomy ( 'writer', 'journal', array (

'Hierarchical' => false,

'Labels' => $ labels,

'Show_ui' => true,

'Query_var' => true,

'Rewrite' => array ('slug' => 'writer'),

));

}

In this code, we refer to the customization of the entry you want to add taxonomies to, recalling must be added to functions.php file of our theme.

Custom Post Type Plugins

Then here are some of the selected plugins that can let you customize the entries.

  • Custom Post Type UI: Very intuitive and easy to use.
  • Toolset Types: In addition to creating custom entries, it allows us to create individualized taxonomies and fields.
  • Pods: A complete plugin that is previously mentioned in the list of other plugins, templates, and other features options.

If you are starting with WordPress, we recommend you to take a look at our post about 50 useful and recommended plugins for Getting Started with WordPress. If you have programming skills or want to know more about the WordPress, you can take advantage of our WordPress Category here (link).

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.