search-extras.php
966 Bytes
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
<?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 exclude_from_search( $query ) {
if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'shows' ) ) {
$current_meta = $query->get('meta_query');
$custom_meta = array(
'key' => 'exclude_from_search',
'type' => 'BINARY',
'value' => '1',
'compare' => '!='
);
$meta_query = $current_meta[] = $custom_meta;
$query->set('meta_query', array($meta_query));
}
}
add_action( 'pre_get_posts', 'exclude_from_search' );
// 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' );