5fea301d by Jeff Balicki

exclude_in_search_results

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent fbd3c19f
...@@ -10,24 +10,29 @@ function add_attachment_mime_type( $attachment_id ){ ...@@ -10,24 +10,29 @@ function add_attachment_mime_type( $attachment_id ){
10 10
11 } 11 }
12 12
13 13 function exclude_in_search_results( $query ) {
14 14
15 15 if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
16 function exclude_from_search( $query ) { 16
17 if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'shows' ) ) { 17 $query->set( 'post_type', array( 'post', 'attachment', 'pages', 'documents', 'documents') );
18 $current_meta = $query->get('meta_query'); 18
19 $custom_meta = array( 19 $query->set( 'meta_query', array (
20 'key' => 'exclude_from_search', 20 'relation' => 'OR',
21 'type' => 'BINARY', 21 array (
22 'value' => '1', 22 'relation' => 'AND',
23 'compare' => '!=' 23 array(
24 ); 24 'key' => 'exclude_from_search',
25 $meta_query = $current_meta[] = $custom_meta; 25 'value' => '1',
26 $query->set('meta_query', array($meta_query)); 26 'compare' => '!=',
27 ),
28 ),
29 ) );
30
27 } 31 }
28 } 32 }
29 add_action( 'pre_get_posts', 'exclude_from_search' ); 33 //add_action( 'pre_get_posts', 'exclude_in_search_results' );
30 34
35
31 36
32 37
33 // apply tags to attachments 38 // apply tags to attachments
......