custom post type wordpress use categories code example

Example 1: wordpress create new post type

/*
- The function you want for creating a custom wordpress post type is 
register_post_type()
- https://developer.wordpress.org/reference/functions/register_post_type/
- To add more meta boxes to the post type search for the support items in the 
above link.
- Below is a basic implementation of the function to register video post type
*/
register_post_type( 'video',
  array(
    'labels' => array(
      'name' => 'Videos',
      'singular_name' => 'Video'
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array(
      'slug' => 'videos'
    ),
    'exclude_from_search'=> true
    ,
    'supports' => array(
      'title','editor','thumbnail'
    )
  )
);

Example 2: create custom post type with category in wordpress functions.php

function create_posttype() {
  register_post_type( 'wpll_product',
    array(
      'labels' => array(
        'name' => __( 'Products' ),
        'singular_name' => __( 'Product' )
      ),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'products'),
    )
  );
}
add_action( 'init', 'create_posttype' );

Tags:

Php Example