1. Home
  2. Advanced
  3. Exclude Newsletter Glue Posts from WordPress Search Results

Exclude Newsletter Glue Posts from WordPress Search Results

To remove the Newsletter Glue post type from WP search, add this snippet to your favorite snippets plugin:

add_filter( 'pre_get_posts', function( $query ) {
    if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
        $post_types = $query->get( 'post_type' );
        
        if ( empty( $post_types ) || $post_types === 'any' ) {
            $post_types = get_post_types( [ 'public' => true ] );
        }
        
        if ( is_string( $post_types ) ) {
            $post_types = explode( ',', $post_types );
        }
        
        $post_types = array_diff( (array) $post_types, [ 'newsletterglue' ] );
        $query->set( 'post_type', array_values( $post_types ) );
    }
    return $query;
} );


Updated on February 27, 2026
Was this article helpful?
Get more help
Can't find the answer you're looking for? Get in touch.
Contact support