Multi-Select

The Multi-Select field creates a list input option for the block, in which multiple choices can be selected.

Settings

  • Help Text: Instructions to describe data needed in the field.
  • Choices: The items you want to make available in the dropdown menu.
    • Enter each choice on a new line.
    • To specify the value and label separately, use this format: value : Your label. The label will display in the block
  • Default Value: The default value for this field when adding the block.
    • Enter each default value on a new line.
    • Use only the value (not the label) of the choice you would like selected.

PHP API Controls

  • name
  • label
  • control
  • type
  • order
  • location
  • width
  • help
  • options
  • default

Template Usage

To display the Multi-Select field in your template, use the field name you provided.

<?php block_field( 'pets-vaccinations' ); ?>

Example template file /blocks/block-block-lab-example.php

<?php
// Block Lab Example Multi-Select Field
?>

<p>Which vaccinations does the pet need?</p>
<p><?php block_field( 'pets-vaccinations' ); ?></p> 

To use the block with the Multi-Select field on your site, locate it in the blocks menu.

Screenshot showing the Block Lab custom block in the menu

It will then display within your post/page.

And on the front-end of your site.

The API will return an array of the values, and echo a comma separated string.

<h2>Featuring:</h2>
<ul>
	<?php foreach ( block_value( 'features' ) as $value ) : ?>
	<li><?php echo $value; ?></li>
	<?php endforeach; ?>
</ul>