Title: WP_Taxonomy::get_rest_controller
Published: August 11, 2020
Last modified: April 28, 2025

---

# WP_Taxonomy::get_rest_controller(): 󠀁[WP_REST_Controller](https://developer.wordpress.org/reference/classes/wp_rest_controller/)󠁿|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/WP_Taxonomy/get_rest_controller/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/classes/WP_Taxonomy/get_rest_controller/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/WP_Taxonomy/get_rest_controller/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_Taxonomy/get_rest_controller/?output_format=md#changelog)

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

Gets the REST API controller for this taxonomy.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/WP_Taxonomy/get_rest_controller/?output_format=md#description)󠁿

Will only instantiate the controller class once per request.

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

 [WP_REST_Controller](https://developer.wordpress.org/reference/classes/wp_rest_controller/)
|null The controller instance, or null if the taxonomy is set not to show in rest.

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

    ```php
    public function get_rest_controller() {
    	if ( ! $this->show_in_rest ) {
    		return null;
    	}

    	$class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Terms_Controller::class;

    	if ( ! class_exists( $class ) ) {
    		return null;
    	}

    	if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) {
    		return null;
    	}

    	if ( ! $this->rest_controller ) {
    		$this->rest_controller = new $class( $this->name );
    	}

    	if ( ! ( $this->rest_controller instanceof $class ) ) {
    		return null;
    	}

    	return $this->rest_controller;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-taxonomy.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-taxonomy.php#L569)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-taxonomy.php#L569-L593)

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

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

## User Contributed Notes

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