Wednesday, May 13, 2015

How to create custom post type in WordPress

 You can create  custom post type by the  simple wordpress  action   hook  just write a action hook

add_action( 'init', 'create_post_type' );

Now you need to write the  function 

function create_post_type() {
  your register post type code here
}

Now in the  function you need to add the  register post type and name   and view permission

  register_post_type( 'mycustom_blog',
    array(
      'labels' => array(
        'name' => __( 'My Blogs' ),
        'singular_name' => __( 'My Blog' )
      ),
      'public' => true,
      'has_archive' => true,
    )

Here  'mycustom_blog ‘ is the  custom post type and  which will save in database to difference the post type .
In the 'labels'  name  of the label which will show in the  backend .
Final code is  you need to add in the  function.php
Is  here

<?php
add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'mycustom_blog',
    array(
      'labels' => array(
        'name' => __( 'My Blogs' ),
        'singular_name' => __( 'My Blog' )
      ),
      'public' => true,
      'has_archive' => true,
    )
  );


} ?>

No comments:

Post a Comment