1/*
2* Creating a function to create our CPT
3*/
4
5function custom_post_type() {
6
7// Set UI labels for Custom Post Type
8 $labels = array(
9 'name' => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
10 'singular_name' => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
11 'menu_name' => __( 'Movies', 'twentytwenty' ),
12 'parent_item_colon' => __( 'Parent Movie', 'twentytwenty' ),
13 'all_items' => __( 'All Movies', 'twentytwenty' ),
14 'view_item' => __( 'View Movie', 'twentytwenty' ),
15 'add_new_item' => __( 'Add New Movie', 'twentytwenty' ),
16 'add_new' => __( 'Add New', 'twentytwenty' ),
17 'edit_item' => __( 'Edit Movie', 'twentytwenty' ),
18 'update_item' => __( 'Update Movie', 'twentytwenty' ),
19 'search_items' => __( 'Search Movie', 'twentytwenty' ),
20 'not_found' => __( 'Not Found', 'twentytwenty' ),
21 'not_found_in_trash' => __( 'Not found in Trash', 'twentytwenty' ),
22 );
23
24// Set other options for Custom Post Type
25
26 $args = array(
27 'label' => __( 'movies', 'twentytwenty' ),
28 'description' => __( 'Movie news and reviews', 'twentytwenty' ),
29 'labels' => $labels,
30 // Features this CPT supports in Post Editor
31 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
32 // You can associate this CPT with a taxonomy or custom taxonomy.
33 'taxonomies' => array( 'genres' ),
34 /* A hierarchical CPT is like Pages and can have
35 * Parent and child items. A non-hierarchical CPT
36 * is like Posts.
37 */
38 'hierarchical' => false,
39 'public' => true,
40 'show_ui' => true,
41 'show_in_menu' => true,
42 'show_in_nav_menus' => true,
43 'show_in_admin_bar' => true,
44 'menu_position' => 5,
45 'can_export' => true,
46 'has_archive' => true,
47 'exclude_from_search' => false,
48 'publicly_queryable' => true,
49 'capability_type' => 'post',
50 'show_in_rest' => true,
51
52 );
53
54 // Registering your Custom Post Type
55 register_post_type( 'movies', $args );
56
57}
58
59/* Hook into the 'init' action so that the function
60* Containing our post type registration is not
61* unnecessarily executed.
62*/
63
64add_action( 'init', 'custom_post_type', 0 );
1/*
2- The function you want for creating a custom wordpress post type is
3register_post_type()
4- https://developer.wordpress.org/reference/functions/register_post_type/
5- To add more meta boxes to the post type search for the support items in the
6above link.
7- Below is a basic implementation of the function to register video post type
8*/
9register_post_type( 'video',
10 array(
11 'labels' => array(
12 'name' => 'Videos',
13 'singular_name' => 'Video'
14 ),
15 'public' => true,
16 'has_archive' => true,
17 'rewrite' => array(
18 'slug' => 'videos'
19 ),
20 'exclude_from_search'=> true
21 ,
22 'supports' => array(
23 'title','editor','thumbnail'
24 )
25 )
26);
1$pt = get_post_type_object( 'books' );
2
3// These two usually contain the post type name in plural.
4// They may differ though.
5echo $pt->label;
6echo $pt->labels->name;
7
8// This one holds the post type name in singular.
9echo $pt->labels->singular_name;
1function book_setup_post_type() {
2 $args = array(
3 'public' => true,
4 'label' => __( 'Books', 'textdomain' ),
5 'menu_icon' => 'dashicons-book',
6 );
7 register_post_type( 'book', $args );
8}
9add_action( 'init', 'book_setup_post_type' );
10
1function custom_post_type() {
2 $labels = array(
3 'name' => _x( 'Movies', 'Post Type General Name', 'twentythirteen' ),
4 'singular_name' => _x( 'Movie', 'Post Type Singular Name', 'twentythirteen' ),
5 'menu_name' => __( 'Movies', 'twentythirteen' ),
6 'parent_item_colon' => __( 'Parent Movie', 'twentythirteen' ),
7 'all_items' => __( 'All Movies', 'twentythirteen' ),
8 'view_item' => __( 'View Movie', 'twentythirteen' ),
9 'add_new_item' => __( 'Add New Movie', 'twentythirteen' ),
10 'add_new' => __( 'Add New', 'twentythirteen' ),
11 'edit_item' => __( 'Edit Movie', 'twentythirteen' ),
12 'update_item' => __( 'Update Movie', 'twentythirteen' ),
13 'search_items' => __( 'Search Movie', 'twentythirteen' ),
14 'not_found' => __( 'Not Found', 'twentythirteen' ),
15 'not_found_in_trash' => __( 'Not found in Trash', 'twentythirteen' ),
16 );
17
18
19 $args = array(
20 'label' => __( 'movies', 'twentythirteen' ),
21 'description' => __( 'Movie news and reviews', 'twentythirteen' ),
22 'labels' => $labels,
23 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
24 'hierarchical' => true,
25 'public' => true,
26 'show_ui' => true,
27 'show_in_menu' => true,
28 'show_in_nav_menus' => true,
29 'show_in_admin_bar' => true,
30 'menu_position' => 5,
31 'can_export' => true,
32 'has_archive' => true,
33 'exclude_from_search' => false,
34 'publicly_queryable' => true,
35 'capability_type' => 'page',
36 'show_in_rest' => true,
37
38 // This is where we add taxonomies to our CPT
39 'taxonomies' => array( 'category' ),
40 );
41
42 // Registering your Custom Post Type
43 register_post_type( 'movies', $args );
44
45}
46
47
48add_action( 'init', 'custom_post_type', 0 );
49
1// Register Custom Post Type
2function custom_post_type() {
3
4 $labels = array(
5 'name' => _x( 'Post Types', 'Post Type General Name', 'text_domain' ),
6 'singular_name' => _x( 'Post Type', 'Post Type Singular Name', 'text_domain' ),
7 'menu_name' => __( 'Post Types', 'text_domain' ),
8 'name_admin_bar' => __( 'Post Type', 'text_domain' ),
9 'archives' => __( 'Item Archives', 'text_domain' ),
10 'attributes' => __( 'Item Attributes', 'text_domain' ),
11 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
12 'all_items' => __( 'All Items', 'text_domain' ),
13 'add_new_item' => __( 'Add New Item', 'text_domain' ),
14 'add_new' => __( 'Add New', 'text_domain' ),
15 'new_item' => __( 'New Item', 'text_domain' ),
16 'edit_item' => __( 'Edit Item', 'text_domain' ),
17 'update_item' => __( 'Update Item', 'text_domain' ),
18 'view_item' => __( 'View Item', 'text_domain' ),
19 'view_items' => __( 'View Items', 'text_domain' ),
20 'search_items' => __( 'Search Item', 'text_domain' ),
21 'not_found' => __( 'Not found', 'text_domain' ),
22 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
23 'featured_image' => __( 'Featured Image', 'text_domain' ),
24 'set_featured_image' => __( 'Set featured image', 'text_domain' ),
25 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
26 'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
27 'insert_into_item' => __( 'Insert into item', 'text_domain' ),
28 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
29 'items_list' => __( 'Items list', 'text_domain' ),
30 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
31 'filter_items_list' => __( 'Filter items list', 'text_domain' ),
32 );
33 $args = array(
34 'label' => __( 'Post Type', 'text_domain' ),
35 'description' => __( 'Post Type Description', 'text_domain' ),
36 'labels' => $labels,
37 'supports' => false,
38 'taxonomies' => array( 'category', 'post_tag' ),
39 'hierarchical' => false,
40 'public' => true,
41 'show_ui' => true,
42 'show_in_menu' => true,
43 'menu_position' => 5,
44 'show_in_admin_bar' => true,
45 'show_in_nav_menus' => true,
46 'can_export' => true,
47 'has_archive' => true,
48 'exclude_from_search' => false,
49 'publicly_queryable' => true,
50 'capability_type' => 'page',
51 );
52 register_post_type( 'post_type', $args );
53
54}
55add_action( 'init', 'custom_post_type', 0 );