Title: _build_block_template_object_from_post_object
Published: July 16, 2024
Last modified: May 20, 2026

---

# _build_block_template_object_from_post_object( WP_Post $post, array $terms = array(), array $meta = array() ): 󠀁[WP_Block_Template](https://developer.wordpress.org/reference/classes/wp_block_template/)󠁿|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Builds a block template object from a post object.

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

This is a helper function that creates a block template object from a given post
object.
It is self-sufficient in that it only uses information passed as arguments;
it does not query the database for additional information.

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

 `$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)required

Template post.

`$terms`arrayoptional

Additional terms to inform the template object.

Default:`array()`

`$meta`arrayoptional

Additional meta fields to inform the template object.

Default:`array()`

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

 [WP_Block_Template](https://developer.wordpress.org/reference/classes/wp_block_template/)
|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Template
or error object.

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

    ```php
    function _build_block_template_object_from_post_object( $post, $terms = array(), $meta = array() ) {
    	if ( empty( $terms['wp_theme'] ) ) {
    		return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.' ) );
    	}
    	$theme = $terms['wp_theme'];

    	$default_template_types = get_default_block_template_types();

    	$template_file  = _get_block_template_file( $post->post_type, $post->post_name );
    	$has_theme_file = get_stylesheet() === $theme && null !== $template_file;

    	$template                 = new WP_Block_Template();
    	$template->wp_id          = $post->ID;
    	$template->id             = $theme . '//' . $post->post_name;
    	$template->theme          = $theme;
    	$template->content        = $post->post_content;
    	$template->slug           = $post->post_name;
    	$template->source         = 'custom';
    	$template->origin         = ! empty( $meta['origin'] ) ? $meta['origin'] : null;
    	$template->type           = $post->post_type;
    	$template->description    = $post->post_excerpt;
    	$template->title          = $post->post_title;
    	$template->status         = $post->post_status;
    	$template->has_theme_file = $has_theme_file;
    	$template->is_custom      = empty( $meta['is_wp_suggestion'] );
    	$template->author         = $post->post_author;
    	$template->modified       = $post->post_modified;

    	if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
    		$template->post_types = $template_file['postTypes'];
    	}

    	if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
    		$template->is_custom = false;
    	}

    	if ( 'wp_template_part' === $post->post_type && isset( $terms['wp_template_part_area'] ) ) {
    		$template->area = $terms['wp_template_part_area'];
    	}

    	return $template;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/block-template-utils.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/block-template-utils.php#L843)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/block-template-utils.php#L843-L884)

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

| Uses | Description | 
| [get_default_block_template_types()](https://developer.wordpress.org/reference/functions/get_default_block_template_types/)`wp-includes/block-template-utils.php` |

Returns a filtered list of default template types, containing their localized titles and descriptions.

  | 
| [_get_block_template_file()](https://developer.wordpress.org/reference/functions/_get_block_template_file/)`wp-includes/block-template-utils.php` |

Retrieves the template file from the theme for a given slug.

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

Retrieves name of the current stylesheet.

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

Retrieves the translation of $text.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/_build_block_template_object_from_post_object/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_build_block_template_object_from_post_object/?output_format=md#)

| Used by | Description | 
| [inject_ignored_hooked_blocks_metadata_attributes()](https://developer.wordpress.org/reference/functions/inject_ignored_hooked_blocks_metadata_attributes/)`wp-includes/block-template-utils.php` |

Inject ignoredHookedBlocks metadata attributes into a template or template part.

  | 
| [_build_block_template_result_from_post()](https://developer.wordpress.org/reference/functions/_build_block_template_result_from_post/)`wp-includes/block-template-utils.php` |

Builds a unified template object based a post Object.

  |

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

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

## User Contributed Notes

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