exclude_from_search
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
1 changed file
with
11 additions
and
13 deletions
| ... | @@ -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 | 15 | ||
| 19 | // append yours | 16 | function exclude_from_search( $query ) { |
| 20 | $meta_query[] = array( | 17 | if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'shows' ) ) { |
| 21 | 'key' => 'exclude_from_search', // please make sure that key is correct | 18 | $current_meta = $query->get('meta_query'); |
| 19 | $custom_meta = array( | ||
| 20 | 'key' => 'exclude_from_search', | ||
| 21 | 'type' => 'BINARY', | ||
| 22 | 'value' => '1', | 22 | 'value' => '1', |
| 23 | 'compare' => '!=' // you can also try 'NOT EXISTS' comparison | 23 | 'compare' => '!=' |
| 24 | ); | 24 | ); |
| 25 | 25 | $meta_query = $current_meta[] = $custom_meta; | |
| 26 | $query->set('meta_query', $meta_query); | 26 | $query->set('meta_query', array($meta_query)); |
| 27 | |||
| 28 | } | 27 | } |
| 29 | } | 28 | } |
| 30 | add_action( 'pre_get_posts', 'exclude_post' ); | 29 | add_action( 'pre_get_posts', 'exclude_from_search' ); |
| 31 | |||
| 32 | 30 | ||
| 33 | 31 | ||
| 34 | 32 | ... | ... |
-
Please register or sign in to post a comment