Title: Indexing post types
Author: WordPress VIP Documentation
Published: March 10, 2021
Last modified: December 17, 2024

---

 1. [Enterprise Search](https://docs.wpvip.com/enterprise-search/)
 2. [Choose what to index](https://docs.wpvip.com/enterprise-search/indexing/)
 3. Indexing post types

#  Indexing post types

Enterprise Search automatically indexes all [public post types](https://developer.wordpress.org/reference/functions/register_post_type/#public).

In this example, a custom function uses `pre_get_posts` to customize search for 
an `event` custom post type. Because the `event` custom post type is public, it 
is in the `post_type` allow list and indexed by default.

    ```lang-php
    add_action( 'pre_get_posts', 'my_event_query_filter' );

    function my_event_query_filter( $query ) {
        if ( $query->is_main_query() && get_query_var( 'events', false ) ) {
            $query->set( 'post_type' ), 'event' );
        }
    }
    ```

**Note**

Indexing can be enabled for _all_ post types, including private post types, by [activating the Protected Content feature](https://docs.wpvip.com/vip-search/vip-search-features/#h-protected-content),
but also risks exposing non-public content to unauthorized users.

## Adding post types to the allow list

Use the `ep_indexable_post_types` filter to customize the indexable post types. 
This filter is useful if there is a need for specific private post types to be indexed,
or to **exclude** specific [public post types ](https://developer.wordpress.org/reference/functions/register_post_type/#public)
from indexing.

The `ep_indexable_post_types` filter uses a list with the below array format:

    ```lang-php
    [
    	'event' => 'event',
    	'post'  => 'post',
    	'page'  => 'page',
    ]
    ```

In this code example, the private post type `attachment` is added to the allow list
for indexing:

    ```lang-php
    function mysite_indexable_post_types( $types ) {
    	$types['attachment'] = 'attachment';
    	return $types;
    }
    add_filter( 'ep_indexable_post_types', 'mysite_indexable_post_types', 10, 1 );
    ```

**Note**

To fully index a post type, be sure to [allow all associated post statuses](https://docs.wpvip.com/enterprise-search/indexing/post-statuses/#adding-or-excluding-post-statuses-to-the-allow-list),
such as `inherit` for attachments.

## Excluding post types from the allow list

To exclude specific post types (e.g. ones which do not contain information that 
will be displayed to users), use the same allow list to block indexing by programmatically
removing the entry.

In this code example, the `ai_log`, `msm_sitemap` , `wlo_option`, `vip-legacy-redirect`
custom post types are excluded from indexing:

    ```lang-php
    function mysite_events_indexable_post_types( $types ) {
    	$deny_list = array( 'ai_log', 'msm_sitemap', 'wlo_option', 'vip-legacy-redirect' );
    	// unset the items with values matching the deny list
    	$types = array_diff( $types, $deny_list );
    	return $types;
    }
    add_filter( 'ep_indexable_post_types', 'mysite_events_indexable_post_types', 10, 1 );
    ```

Last updated: December 17, 2024