Skip to content
Block Controls

Taxonomy

Taxonomy control lets you search and select terms from any WordPress taxonomy (categories, tags, or custom taxonomies).

Taxonomy Control

Only taxonomies registered with show_in_rest => true will appear in the control. If your custom taxonomy is not showing up, add this parameter:

register_taxonomy('your_taxonomy', 'post', [
    // ... other parameters
    'show_in_rest' => true,
]);

Control Settings

  • Taxonomy (taxonomy) - where the terms come from, category by default. The list holds every taxonomy the REST API exposes
  • Appearance (taxonomy_appearance) - Select by default, a searchable dropdown. Radio puts one input per term on screen and is labelled Checkbox while Multiple is on. Token Field takes terms as removable tokens
  • Output Format (taxonomy_output_format) - what the control stores. Term Slug by default, or Term ID, or Term Object, which stores the ID and turns it into a WP_Term when the block renders
  • Multiple (multiple) - off by default. Stores an array of terms instead of one

Output Format decides what is written into the block, not how an existing value is read, so blocks saved before you switch from Term Slug to Term ID keep their slugs until the term is picked again.

Usage Examples

Basic Usage (Term Slug)

PHP
<?php
$term = get_term_by('slug', $attributes['control_name'], 'category');
if ($term && !is_wp_error($term)) {
    echo '<span class="term">' . esc_html($term->name) . '</span>';
}
?>

Multiple Terms

PHP
<?php if ($attributes['control_name']) : ?>
    <ul class="terms-list">
        <?php foreach($attributes['control_name'] as $term_slug) :
            $term = get_term_by('slug', $term_slug, 'category');
            if ($term && !is_wp_error($term)) : ?>
                <li class="term-<?php echo esc_attr($term->slug); ?>">
                    <?php echo esc_html($term->name); ?>
                </li>
            <?php endif;
        endforeach; ?>
    </ul>
<?php endif; ?>

Using Term Object

PHP
<?php if ($attributes['control_name']) : ?>
    <div class="term-<?php echo esc_attr($attributes['control_name']->slug); ?>">
        <h4><?php echo esc_html($attributes['control_name']->name); ?></h4>
        <p><?php echo esc_html($attributes['control_name']->description); ?></p>
    </div>
<?php endif; ?>

Handlebars Usage

Set Output Format to Term Object when using Handlebars templates.

Single Term
<div class="term-{{control_name.slug}}">
  {{control_name.name}}
</div>
Multiple Terms
<ul class="terms-list">
  {{#each control_name}}
    <li class="term-{{this.slug}}">
      {{this.name}}
    </li>
  {{/each}}
</ul>

Post Meta

Post Meta
<?php
$term_slug = get_lzb_meta('control_meta_name');
if ($term_slug) {
    $term = get_term_by('slug', $term_slug, 'category');
    if ($term && !is_wp_error($term)) {
        echo '<span class="term">' . esc_html($term->name) . '</span>';
    }
}
?>

Use Term Object format to access all term data without additional database queries.

Was this article helpful?

Copyright © 2026 Lazy Blocks.