Saturday 1 February 2014

How To Create Custom Post Types

WordPress has an awesome feature which is known as custom post types which are useful to organize and a different kinds of posts.

In this tutorial i will explain you about creating posts for your wordpress blog. There are two methods to create custom post types.
1. By Hardcoding.
2. By Installing plugin.

We must know both of the methods for creating custom post types.
If you hardcode you have to add the following code in the functions.php which is located in your theme files.


add_action('init', 'cptui_register_my_cpt');
function cptui_register_my_cpt() {
register_post_type('movies', array(
'label' => '__('movie')',
'description' => '',
'public' => 'true',
'show_ui' => 'true',
'show_in_menu' => 'true',
'capability_type' => 'post',
'hierarchical' => 'false',
'rewrite' => array('slug' => 'movies', 'with_front' => '1'),
'query_var' => 'true',
'exclude_from_search' => 'false',
'supports' => array(''title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats','),
'labels' => 'array (
  'name' => 'movie',
  'singular_name' => '',
  'menu_name' => 'movie',
  'add_new' => 'Add movie',
  'add_new_item' => 'Add New movie',
  'edit' => 'Edit',
  'edit_item' => 'Edit movie',
  'new_item' => 'New movie',
  'view' => 'View movie',
  'view_item' => 'View movie',
  'search_items' => 'Search movie',
  'not_found' => 'No movie Found',
  'not_found_in_trash' => 'No movie Found in Trash',
  'parent' => 'Parent movie',
)'
) ); }
now you have created a custom post type called movie. 2. If want to make custom post types with plugin then follow install a plugin called Custom Post Type UI

1 comment:

  1. here is a simple tut for looping of custom post type posts..
    http://kvcodes.com/2014/03/loop-specific-post-type-and-categories/

    ReplyDelete