Title: WP_REST_Search_Controller::sanitize_subtypes
Published: December 6, 2018
Last modified: August 20, 2026

---

# WP_REST_Search_Controller::sanitize_subtypes( string|array $subtypes, WP_REST_Request $request, string $parameter ): string[]|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#wp--skip-link--target)

Sanitizes the list of subtypes, to ensure only subtypes of the passed type are included.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#parameters)󠁿

 `$subtypes`string|arrayrequired

One or more subtypes.

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
required

Full details about the request.

`$parameter`stringrequired

Parameter name.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#return)󠁿

 string[]|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
List of valid subtypes, or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#source)󠁿

    ```php
    public function sanitize_subtypes( $subtypes, $request, $parameter ) {
    	$subtypes = wp_parse_slug_list( $subtypes );

    	$subtypes = rest_parse_request_arg( $subtypes, $request, $parameter );
    	if ( is_wp_error( $subtypes ) ) {
    		return $subtypes;
    	}

    	// 'any' overrides any other subtype.
    	if ( in_array( self::TYPE_ANY, $subtypes, true ) ) {
    		return array( self::TYPE_ANY );
    	}

    	$handler = $this->get_search_handler( $request );
    	if ( is_wp_error( $handler ) ) {
    		return $handler;
    	}

    	return array_intersect( $subtypes, $handler->get_subtypes() );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php#L369)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php#L369-L388)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Search_Controller::get_search_handler()](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/get_search_handler/)`wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php` |

Gets the search handler to handle the current request.

  | 
| [rest_parse_request_arg()](https://developer.wordpress.org/reference/functions/rest_parse_request_arg/)`wp-includes/rest-api.php` |

Parse a request argument based on details registered to the route.

  | 
| [wp_parse_slug_list()](https://developer.wordpress.org/reference/functions/wp_parse_slug_list/)`wp-includes/functions.php` |

Cleans up an array, comma- or space-separated list of slugs.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/sanitize_subtypes/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_search_controller%2Fsanitize_subtypes%2F)
before being able to contribute a note or feedback.