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