search-extras.php
3.52 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
<?php
add_action( 'add_attachment', 'add_attachment_mime_type' );
function add_attachment_mime_type( $attachment_id ){
$post = get_post( $attachment_id );
$post_mime_type = explode(".", $post->_wp_attached_file);
update_post_meta( $attachment_id, 'file_type', end($post_mime_type) );
}
function wporg_custom_post_type() {
register_post_type('documents',
array(
'labels' => array(
'name' => __( 'Documents', 'textdomain' ),
'singular_name' => __( 'Documents', 'textdomain' ),
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'documents' ), // my custom slug
)
);
}
//add_action('init', 'wporg_custom_post_type');
function wptp_add_categories_to_attachments() {
register_taxonomy_for_object_type( 'category', 'attachment' );
// register_taxonomy_for_object_type( 'continent', 'attachment' );
// register_taxonomy_for_object_type( 'country', 'attachment' );
// register_taxonomy_for_object_type( 'region', 'attachment' );
}
//add_action( 'init' , 'wptp_add_categories_to_attachments' );
// apply tags to attachments
function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
// register new taxonomy which applies to attachments
function wptp_add_taxonomy() {
$labels = array(
'name' => 'Continent',
'singular_name' => 'Continent',
'search_items' => 'Search Continent',
'all_items' => 'All Continent',
'parent_item' => 'Parent Continent',
'parent_item_colon' => 'Parent Continent:',
'edit_item' => 'Edit Continent',
'update_item' => 'Update Continent',
'add_new_item' => 'Add New Continent',
'new_item_name' => 'New Continent Name',
'menu_name' => 'Continent',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true',
);
register_taxonomy( 'continent',[ 'attachment','documents'], $args );
$labels = array(
'name' => 'Region',
'singular_name' => 'Region',
'search_items' => 'Search Region',
'all_items' => 'All Region',
'parent_item' => 'Parent Region',
'parent_item_colon' => 'Parent Region:',
'edit_item' => 'Edit Region',
'update_item' => 'Update Region',
'add_new_item' => 'Add New Region',
'new_item_name' => 'New Region Name',
'menu_name' => 'Region',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true',
);
register_taxonomy( 'region',[ 'attachment','documents'], $args );
$labels = array(
'name' => 'Country',
'singular_name' => 'Country',
'search_items' => 'Search Country',
'all_items' => 'All Country',
'parent_item' => 'Parent Country',
'parent_item_colon' => 'Parent Country:',
'edit_item' => 'Edit Country',
'update_item' => 'Update Country',
'add_new_item' => 'Add New Country',
'new_item_name' => 'New Country Name',
'menu_name' => 'Country',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true',
);
register_taxonomy( 'country',[ 'attachment','documents'], $args );
}
//add_action( 'init', 'wptp_add_taxonomy' , 0 );