Adding a custom post type in wordpress is an easy task. You can learn a lot at at WordPress Codex about Post types.WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.
Minimum Code required to create a custom post type is following. This basic code has been taken from wordpress codex and this code will create a “Product” custom post type with minimum options. However below the basic code we have added advanced snippet with more arguments.
Advanced Snippet to add Custom Post types in WordPress. One just need to add the following code in functions.php file to make a Portfolio custom post type. If you want a custom post type other then Portfolio, you can just replace word Portfolio with your Post Type name such as Event or Product. If you want to add more then one custom post type don’t forget to change function name everytime you create a custom post type. Make sure you write this code before php closing tag in functions.php
[box style=”green”]If you face a blank screen after adding this code, and you can no longer access wordpress, you have played wrong with php syntax. That means you have opened <?php tag again before closing previous one. [/box]
If you face any problem while using this code, just write in a comment below.
A website developer, loves #wordpress #drupal #php. Love posting about wordpress, php, bootstrap and SEO. Also provide online/offline training on wordpress, drupal, php and SEO. I am available on Twitter @ anibabbar , Skype @anibabbar , gmail @anibabbar !! facebook @thinkncode.com
About us and this blog
We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.