wppaste
WordPress

render_block_core_term_template( array $attributes, string $content, WP_Block $block ): string

Since
6.9.0
Source
wp-includes/blocks/term-template.php:19
Renders the core/term-template block on the server.

Compatibility

WordPress
since 6.9.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$attributesarray
Block attributes.
$contentstring
Block default content.
$blockWP_Block
Block instance.

Return value

string
Returns the output of the term template.

Performance profile

How much work a call to render_block_core_term_template() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8

Executed per call on PHP 8.5. The body compiles to 180.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action()one call below render_block_core_term_template()

Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_term_template() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev180817
8.5180817
8.41808172 fewer instructions than PHP 8.3
8.3182817
8.2182817
8.1182817
7.4182817

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 13

Show all 13

Source code

function render_block_core_term_template( $attributes, $content, $block ) {	if ( ! isset( $block->context ) || empty( $block->context['termQuery'] ) ) {		return '';	} 	$query = $block->context['termQuery']; 	$query_args = array(		'number'     => $query['perPage'],		'order'      => $query['order'],		'orderby'    => $query['orderBy'],		'hide_empty' => $query['hideEmpty'],	); 	$inherit_query = isset( $query['inherit'] )		&& $query['inherit']		&& ( is_tax() || is_category() || is_tag() ); 	if ( $inherit_query ) {		// Get the current term and taxonomy from the queried object.		$queried_object = get_queried_object(); 		// For hierarchical taxonomies, show children of the current term.		// For non-hierarchical taxonomies, show all terms (don't set parent).		if ( is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {			// If showNested is true, use child_of to include nested terms.			// Otherwise, use parent to show only direct children.			if ( ! empty( $query['showNested'] ) ) {				$query_args['child_of'] = $queried_object->term_id;			} else {				$query_args['parent'] = $queried_object->term_id;			}		}		$query_args['taxonomy'] = $queried_object->taxonomy;	} else {		// If not inheriting set `taxonomy` from the block attribute.		$query_args['taxonomy'] = $query['taxonomy']; 		// If we are including specific terms we ignore `showNested` argument.		if ( ! empty( $query['include'] ) ) {			$query_args['include'] = array_unique( array_map( 'intval', $query['include'] ) );			$query_args['orderby'] = 'include';			$query_args['order']   = 'asc';		} elseif ( is_taxonomy_hierarchical( $query['taxonomy'] ) && empty( $query['showNested'] ) ) {			// We set parent only when inheriting from the taxonomy archive context or not			// showing nested terms, otherwise nested terms are not displayed.			$query_args['parent'] = 0;		}	} 	$terms_query = new WP_Term_Query( $query_args );	$terms       = $terms_query->get_terms(); 	if ( ! $terms || is_wp_error( $terms ) ) {		return '';	} 	$content = '';	foreach ( $terms as $term ) {		// Get an instance of the current Term Template block.		$block_instance = $block->parsed_block; 		// Set the block name to one that does not correspond to an existing registered block.		// This ensures that for the inner instances of the Term Template block, we do not render any block supports.		$block_instance['blockName'] = 'core/null'; 		$term_id  = $term->term_id;		$taxonomy = $term->taxonomy; 		$filter_block_context = static function ( $context ) use ( $term_id, $taxonomy ) {			$context['termId']   = $term_id;			$context['taxonomy'] = $taxonomy;			return $context;		}; 		// Use an early priority to so that other 'render_block_context' filters have access to the values.		add_filter( 'render_block_context', $filter_block_context, 1 ); 		// Render the inner blocks of the Term Template block with `dynamic` set to `false` to prevent calling		// `render_callback` and ensure that no wrapper markup is included.

Changelog

Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/term-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.