-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_post_type.php
More file actions
133 lines (113 loc) · 3.94 KB
/
custom_post_type.php
File metadata and controls
133 lines (113 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/* Custom Post Type
* Separate file for adding custom post types to your theme.
* -Includes a single custom taxonomy example for category and tag
* -Comment out "taxonomies" line 127 if not using any taxonomies.
* -Use Find and Replace to add POSTTYPENAME and BODYSLUG across the file.
* Version 1.1
*/
// Register CATEGORYNAME to 'POSTTYPENAME' - remove if not using category
function register_cpt_category1() {
/**
* Taxonomy: CATEGORYNAME
*/
$labels = array(
"name" => __( "CATEGORYNAME", "BODYSLUG" ),
"singular_name" => __( "CATEGORYNAME", "BODYSLUG" ),
);
$args = array(
"label" => __( "CATEGORYNAME", "BODYSLUG" ),
"labels" => $labels,
"public" => true,
"hierarchical" => false,
"label" => "CATEGORYNAME",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'CATEGORYNAME', 'with_front' => true, ),
"show_admin_column" => false,
"show_in_rest" => true,
"rest_base" => "CATEGORYNAME",
'rest_controller_class' => 'WP_REST_Terms_Controller',
"show_in_quick_edit" => false,
);
register_taxonomy( "CATEGORYNAME", array( "POSTTYPENAME" ), $args );
}
add_action( 'init', 'register_cpt_category1' );
// Register TAGNAME to 'POSTTYPENAME' - remove if not using tag
function register_cpt_tag1() {
/**
* Taxonomy: TAGNAME
*/
$labels = array(
"name" => __( "TAGNAME", "BODYSLUG" ),
"singular_name" => __( "TAGNAME", "BODYSLUG" ),
);
$args = array(
"label" => __( "TAGNAME", "BODYSLUG" ),
"labels" => $labels,
"public" => true,
"hierarchical" => false,
"label" => "TAGNAME",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'TAGNAME', 'with_front' => true, ),
"show_admin_column" => false,
"show_in_rest" => true,
"rest_base" => "TAGNAME",
'rest_controller_class' => 'WP_REST_Terms_Controller',
"show_in_quick_edit" => false,
);
register_taxonomy( "TAGNAME", array( "POSTTYPENAME" ), $args );
}
add_action( 'init', 'register_cpt_tag1' );
// Register Custom Post Type: 'POSTTYPENAME'
function register_cpt() {
/**
* Post Type: POSTTYPENAME
*/
$labels = array(
"name" => __( "POSTTYPENAME", "BODYSLUG" ),
"singular_name" => __( "POSTTYPENAME", "BODYSLUG" ),
"menu_name" => __( "POSTTYPENAME", "BODYSLUG" ),
"all_items" => __( "All POSTTYPENAME", "BODYSLUG" ),
"add_new" => __( "Add New", "BODYSLUG" ),
"add_new_item" => __( "Add New POSTTYPENAME", "BODYSLUG" ), //SINGULAR
"edit_item" => __( "Edit POSTTYPENAME", "BODYSLUG" ), //SINGULAR
"new_item" => __( "New POSTTYPENAME", "BODYSLUG" ), //SINGULAR
"view_item" => __( "View POSTTYPENAME Page", "BODYSLUG" ), //SINGULAR
"view_items" => __( "View POSTTYPENAME", "BODYSLUG" ),
"search_items" => __( "Search POSTTYPENAME", "BODYSLUG" ),
"not_found" => __( "No POSTTYPENAME Found", "BODYSLUG" ),
"not_found_in_trash" => __( "No POSTTYPENAME Found in Trash", "BODYSLUG" ),
"archives" => __( "POSTTYPENAME Archives", "BODYSLUG" ), //SINGULAR
);
$args = array(
"label" => __( "POSTTYPENAME", "BODYSLUG" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => true,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "POSTTYPENAME", "with_front" => true ), //SINGULAR
"query_var" => true,
"menu_position" => 20,
"menu_icon" => "dashicons-id-alt",
"supports" => array( "title", "editor", "thumbnail", "excerpt", "custom-fields", "page-attributes" ),
"taxonomies" => array( "CATEGORYNAME", "TAGNAME" ), //REPLACE WITH TAXONOMY NAMES - Find and Replace should take care of these, but double-check!!
);
register_post_type( "POSTTYPENAME", $args ); //SINGULAR
}
add_action( 'init', 'register_cpt' );