Title: Indexing post taxonomies
Author: WordPress VIP Documentation
Published: March 10, 2021
Last modified: December 22, 2023

---

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

#  Indexing post taxonomies

Similar to [post types](https://docs.wpvip.com/vip-search/post-types/), any registered
taxonomy that is **public** will be indexed by default.

E.g. If the taxonomy was registered with [register_taxonomy](https://developer.wordpress.org/reference/functions/register_taxonomy/)
and the `public` or `publicly_queryable` attributes were left to the default of `
true`, or explicitly set to `true`, they will already be in the _allow list_. Otherwise,
they will need to be added. Alternatively, if they are public but you’d prefer to
not allow searches on them, you can disallow them using [the same technique as post types](https://docs.wpvip.com/vip-search/post-types/#adding-or-excluding-post-types-to-the-allow-list).

## Adding or excluding post taxonomies to an allow list

If you want to customize the post taxonomies being indexed, use the `vip_search_post_taxonomies_allow_list`
filter. 

For example, if we want to index the `event-format` and `event-city` taxonomies 
only for the `event` post_type:

    ```lang-php
    add_filter( 'vip_search_post_taxonomies_allow_list', 'mysite_events_indexable_post_tax', 10, 2 );

    function mysite_events_indexable_post_tax( $taxonomy_names, $post ) {
    	if ( is_object( $post ) && 'event' === $post->post_type ) {
    		$taxonomy_names[] = 'event-format';
    		$taxonomy_names[] = 'event-city';
    	}

    	return $taxonomy_names;
    }
    ```

The convention above builds an indexed array.

    ```lang-php
    [
    	'event-format',
    	'event-city',
    ]
    ```

Alternatively, if there are certain taxonomies that should **not** be indexed, you
can use the same filter as above:

    ```lang-php
    function mysite_indexable_post_tax( $taxonomy_names, $post ) {
    	$exclude_list = array( 'event-format', 'event-city' );
    	// unset the items with values matching the deny list
    	$types = array_diff( $taxonomy_names, $exclude_list );

    	return $types;
    }
    add_filter( 'vip_search_post_taxonomies_allow_list', 'mysite_indexable_post_tax', 10, 2 );
    ```

## Taxonomies must be indexed to be used in queries

For example, our custom post type of `event` has at two terms for the `event-format`
taxonomy: `virtual`, and `in_person`. We have a search that includes a taxonomy 
query in the arguments:

    ```lang-php
    'tax_query' => array(
    	array(
    		'taxonomy' => 'event-format',
    		'field'    => 'slug',
    		'terms'    => $format
    	)
    ),
    ```

The `$format` variable (coming from the search form or a query parameter) indicates
whether the user is looking for `virtual`, `in_person`, both (in an array), or a
future format that hasn’t been implemented yet.

Last updated: December 22, 2023