Title: _wp_build_title_and_description_for_single_post_type_block_template
Published: November 2, 2022
Last modified: August 20, 2026

---

# _wp_build_title_and_description_for_single_post_type_block_template( string $post_type, string $slug, WP_Block_Template $template ): bool

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_build_title_and_description_for_single_post_type_block_template/?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 the title and description of a post-specific template based on the underlying
referenced post.

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

Mutates the underlying template object.

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

 `$post_type`stringrequired

Post type, e.g. page, post, product.

`$slug`stringrequired

Slug of the post, e.g. a-story-about-shoes.

`$template`[WP_Block_Template](https://developer.wordpress.org/reference/classes/wp_block_template/)
required

Template to mutate adding the description and title computed.

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

 bool Returns true if the referenced post was found and false otherwise.

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

    ```php
    function _wp_build_title_and_description_for_single_post_type_block_template( $post_type, $slug, WP_Block_Template $template ) {
    	$post_type_object = get_post_type_object( $post_type );

    	$default_args = array(
    		'post_type'              => $post_type,
    		'post_status'            => 'publish',
    		'posts_per_page'         => 1,
    		'update_post_meta_cache' => false,
    		'update_post_term_cache' => false,
    		'ignore_sticky_posts'    => true,
    		'no_found_rows'          => true,
    	);

    	$args = array(
    		'name' => $slug,
    	);
    	$args = wp_parse_args( $args, $default_args );

    	$posts_query = new WP_Query( $args );

    	if ( empty( $posts_query->posts ) ) {
    		$template->title = sprintf(
    			/* translators: Custom template title in the Site Editor referencing a post that was not found. 1: Post type singular name, 2: Post type slug. */
    			__( 'Not found: %1$s (%2$s)' ),
    			$post_type_object->labels->singular_name,
    			$slug
    		);

    		return false;
    	}

    	$post_title = $posts_query->posts[0]->post_title;

    	$template->title = sprintf(
    		/* translators: Custom template title in the Site Editor. 1: Post type singular name, 2: Post title. */
    		__( '%1$s: %2$s' ),
    		$post_type_object->labels->singular_name,
    		$post_title
    	);

    	$template->description = sprintf(
    		/* translators: Custom template description in the Site Editor. %s: Post title. */
    		__( 'Template for %s' ),
    		$post_title
    	);

    	$args = array(
    		'title' => $post_title,
    	);
    	$args = wp_parse_args( $args, $default_args );

    	$posts_with_same_title_query = new WP_Query( $args );

    	if ( count( $posts_with_same_title_query->posts ) > 1 ) {
    		$template->title = sprintf(
    			/* translators: Custom template title in the Site Editor. 1: Template title, 2: Post type slug. */
    			__( '%1$s (%2$s)' ),
    			$template->title,
    			$slug
    		);
    	}

    	return true;
    }
    ```

[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.1/src/wp-includes/block-template-utils.php#L686)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/block-template-utils.php#L686-L749)

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

| Uses | Description | 
| [WP_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_query/__construct/)`wp-includes/class-wp-query.php` |

Constructor.

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

Retrieves the translation of $text.

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

Merges user defined arguments into defaults array.

  | 
| [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.

  |

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

| Used by | Description | 
| [_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/_wp_build_title_and_description_for_single_post_type_block_template/?output_format=md#changelog)󠁿

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

## User Contributed Notes

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