fbd3c19f by Jeff Balicki

exclude_from_search

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent a62eece5
...@@ -10,25 +10,23 @@ function add_attachment_mime_type( $attachment_id ){ ...@@ -10,25 +10,23 @@ function add_attachment_mime_type( $attachment_id ){
10 10
11 } 11 }
12 12
13 function exclude_post( $query ) {
14 if ( $query->is_main_query() ) {
15 13
16 14
17 $meta_query = $query->get('meta_query') ? $query->get('meta_query') : array();
18
19 // append yours
20 $meta_query[] = array(
21 'key' => 'exclude_from_search', // please make sure that key is correct
22 'value' => '1',
23 'compare' => '!=' // you can also try 'NOT EXISTS' comparison
24 );
25
26 $query->set('meta_query', $meta_query);
27
28 }
29 }
30 add_action( 'pre_get_posts', 'exclude_post' );
31 15
16 function exclude_from_search( $query ) {
17 if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'shows' ) ) {
18 $current_meta = $query->get('meta_query');
19 $custom_meta = array(
20 'key' => 'exclude_from_search',
21 'type' => 'BINARY',
22 'value' => '1',
23 'compare' => '!='
24 );
25 $meta_query = $current_meta[] = $custom_meta;
26 $query->set('meta_query', array($meta_query));
27 }
28 }
29 add_action( 'pre_get_posts', 'exclude_from_search' );
32 30
33 31
34 32
......