WP_REST_Template_Revisions_Controller::get_parent()protectedWP 6.4.0

Gets the parent post, if the template ID is valid.

Method of the class: WP_REST_Template_Revisions_Controller{}

No Hooks.

Return

WP_Post|WP_Error. Post object if ID is valid, WP_Error otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_parent( $parent_template_id );
$parent_template_id(string) (required)
Supplied ID.

Changelog

Since 6.4.0 Introduced.

WP_REST_Template_Revisions_Controller::get_parent() code WP 6.7.1

protected function get_parent( $parent_template_id ) {
	$template = get_block_template( $parent_template_id, $this->parent_post_type );

	if ( ! $template ) {
		return new WP_Error(
			'rest_post_invalid_parent',
			__( 'Invalid template parent ID.' ),
			array( 'status' => 404 )
		);
	}

	return get_post( $template->wp_id );
}