Custom Post in WordPress

In below example I have added 2 custom posts in WordPress (with different parameters)

  1. Videos
  2. News

Add the following code in functions.php and it will create menu in admin panel for videos and news.

add_action( ‘init’, ‘create_post_type’ );
function create_post_type() {
register_post_type( ‘my_video’,
array(
‘labels’ => array(
‘name’ => __( ‘Videos’ ),
‘singular_name’ => __( ‘Video’ )
),
‘public’ => true,
‘has_archive’ => true,
)
);
register_post_type( ‘my_news’,
array(
‘supports’ => array( ‘title’,’editor’,’thumbnail’ ),
‘labels’ => array(
‘name’ => __( ‘News’ ),
‘singular_name’ => __( ‘News’ ),
‘public’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’=>’news’),
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ =>null,
),
‘public’ => true,
‘has_archive’ => true,
)
);
}
add_post_type_support( ‘acme_video’, ‘custom-fields’);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.