-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_types.php
86 lines (79 loc) · 3.19 KB
/
post_types.php
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
<?php // CUSTOM POST-TYPE EXAMPLE
add_action('init', 'add_custom_post_types');
function add_custom_post_types(){
$taxonomies = array(
'product_category' => array(
'post_types' => 'product',
'plural' => 'Product Categories',
'singular' => 'Product Category',
'hierarchical' => true
),
'classification' => array(
'post_types' => 'product',
'plural' => 'Classifications',
'singular' => 'Classification',
'hierarchical' => false
)
);
foreach($taxonomies as $t => $o){
extract($o);
// https://codex.wordpress.org/Function_Reference/register_taxonomy
register_taxonomy(
$t,
$post_types,
array(
'labels' => array(
'name' => _x($plural, 'taxonomy general name'),
'singular_name' => _x($singular, 'taxonomy singular name'),
'all_items' => __('All '.$plural),
'edit_item' => __('Edit '.$singular),
'view_item' => __('View '.$singular),
'update_item' => __('Update '.$singular),
'add_new_item' => __('Add New '.$singular),
'new_item_name' => __('New '.$singular.' Name'),
'search_items' => __('Search '.$plural),
'add_or_remove_items' => __('Add or remove '.strtolower($plural)),
'choose_from_most_used' => __('Choose from most used '.strtolower($plural)),
'not_found' => __('No '. strtolower($plural).' found')
),
'hierarchical' => $hierarchical,
'public' => true,
'show_admin_column' => true
)
);
}
// https://codex.wordpress.org/Function_Reference/register_post_type
register_post_type('product',
array(
'labels' => array(
'name' => __('Products', THEME_DOMAIN),
'singular_name' => __('Product', THEME_DOMAIN),
'add_new_item' => __('Add New Product', THEME_DOMAIN),
'view_item' => __('View Product', THEME_DOMAIN),
'edit_item' => __('Edit Product', THEME_DOMAIN)
),
'description' => '',
'public' => TRUE,
'menu_position' => 5,
'menu_icon' => 'dashicons-products',
'has_archive' => TRUE,
'taxonomies' => array('product_category', 'classification'),
'supports' => array(
'title',
'editor',
// 'author',
'thumbnail',
'excerpt',
// 'trackbacks',
'custom-fields',
// 'comments',
'revisions',
'page-attributes',
// 'post-formats'
),
'rewrite' => array(
'slug' => 'products'
)
)
);
}