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 ){
}
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));
function exclude_in_search_results( $query ) {
if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
$query->set( 'post_type', array( 'post', 'attachment', 'pages', 'documents', 'documents') );
$query->set( 'meta_query', array (
'relation' => 'OR',
array (
'relation' => 'AND',
array(
'key' => 'exclude_from_search',
'value' => '1',
'compare' => '!=',
),
),
) );
}
}
add_action( 'pre_get_posts', 'exclude_from_search' );
}
//add_action( 'pre_get_posts', 'exclude_in_search_results' );
// apply tags to attachments
......