# bbPress: Keep Forum Posts Out of Site Search

> Removes forums, topics and replies from your main WordPress search results so blog searches stay focused; bbPress's own forum search still works.

- Type: PHP
- Runs: Frontend only
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: bbpress, search, forums
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bbpress-exclude-from-site-search/

## Code

```php
if ( ! function_exists( 'bbp_get_topic_post_type' ) ) {
    return;
}

add_action( 'pre_get_posts', function ( $query ) {
    if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() || bbp_is_search() ) {
        return;
    }

    $types = $query->get( 'post_type' );

    if ( ! $types || 'any' === $types ) {
        $types = get_post_types( array( 'exclude_from_search' => false ) );
    }

    $query->set( 'post_type', array_values( array_diff( (array) $types, array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) );
} );
```

## Notes

The forum search box (bbPress search) is not affected.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "bbPress: Keep Forum Posts Out of Site Search" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
