Controls
Taxonomy
Taxonomy control creates a dynamic set of taxonomies to search and select from and used to store a taxonomy term slug for the block. See examples below to use this control.
Control Settings
- Taxonomy – select the taxonomy to display in the control (e.g.
Categories
,Tags
, etc...) - Appearance – display control as
Select
,Checkbox
orRadio
- Output Format – specifies the returned value format. Choose from
Term Slug
,Term ID
orTerm Object
(WP_Taxonomy) - Multiple – select a single or multiple taxonomies
Usage
PHP
$selected_taxonomy = get_term_by('slug', $attributes['control_name'], 'category');
?>
<p>
<?php echo $selected_taxonomy->name; ?>
</p>
PHP + Multiple
<?php foreach( $attributes['control_name'] as $term_slug ): ?>
<?php
$selected_taxonomy = get_term_by('slug', $term_slug, 'category');
?>
<p>
<?php echo $selected_taxonomy->name; ?>
</p>
<?php endforeach; ?>
PHP with Output Format as Taxonomy Object
<p>
<?php echo $attributes['control_name']->name; ?>
</p>
<p>
<?php echo $attributes['control_name']->slug; ?>
</p>
To use Taxonomy control with Handlebars, you should set the
Output Format
option to Term Object
, because we don't have a specific Handlebars helper to work with WordPress terms.Handlebars
<p>
{{control_name.name}}
</p>
Handlebars + Multiple
{{#each control_name}}
<p>
{{this.name}}
</p>
{{/each}}
Post Meta
<p>
<?php echo get_lzb_meta( 'control_meta_name' ); ?>
</p>