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
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
- Scaling
- Constant
- Instructions
- 8
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 180.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 180 | 8 | 17 | |
| 8.5 | 180 | 8 | 17 | |
| 8.4 | 180 | 8 | 17 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 182 | 8 | 17 | |
| 8.2 | 182 | 8 | 17 | |
| 8.1 | 182 | 8 | 17 | |
| 7.4 | 182 | 8 | 17 |
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
- is_tax()Determines whether the query is for an existing custom taxonomy archive page.
- is_category()Determines whether the query is for an existing category archive page.
- is_tag()Determines whether the query is for an existing tag archive page.
- get_queried_object()Retrieves the currently queried object.
- is_taxonomy_hierarchical()Determines whether the taxonomy object is hierarchical.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- add_filter()Adds a callback function to a filter hook.
- remove_filter()Removes a callback function from a filter hook.
- esc_attr()Escaping for HTML attributes.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- WP_Term_Query::__construct()Constructor.
- new WP_Block($block_instance)::render()
Show all 13
- WP_Block::__construct()Constructor.
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.
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.