Title: WP_REST_Templates_Controller::__construct
Published: July 20, 2021
Last modified: May 20, 2026

---

# WP_REST_Templates_Controller::__construct( string $post_type )

## In this article

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

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

Constructor.

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

 `$post_type`stringrequired

Post type.

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

    ```php
    public function __construct( $post_type ) {
    	$this->post_type = $post_type;
    	$obj             = get_post_type_object( $post_type );
    	$this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
    	$this->namespace = ! empty( $obj->rest_namespace ) ? $obj->rest_namespace : 'wp/v2';
    }
    ```

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

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

| Uses | Description | 
| [get_post_type_object()](https://developer.wordpress.org/reference/functions/get_post_type_object/)`wp-includes/post.php` |

Retrieves a post type object by name.

  |

| Used by | Description | 
| [WP_REST_Template_Autosaves_Controller::__construct()](https://developer.wordpress.org/reference/classes/wp_rest_template_autosaves_controller/__construct/)`wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php` |

Constructor.

  | 
| [WP_REST_Template_Revisions_Controller::__construct()](https://developer.wordpress.org/reference/classes/wp_rest_template_revisions_controller/__construct/)`wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php` |

Constructor.

  |

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

| Version | Description | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.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_templates_controller%2F__construct%2F)
before being able to contribute a note or feedback.