-
Notifications
You must be signed in to change notification settings - Fork 8
Multiselect
Radoslav Georgiev edited this page Oct 21, 2018
·
3 revisions
The Multiselect field in Ultimate Fields builds on top of the select field while allowing users to select multiple options. Because of this, there are changes in the inputs of the field:
- Instead of a standard
<select>
element, this field adds themultiple
attribute in order to allow multiple options to be selected. In this mode the Select2 plugin is always enabled, as standard browser multi-selects are extremely user-unfriendly. - Instead of the
radio
input type of the Select field, the Multiselect introducescheckbox
as an input type.
The Multiselect field is based on and extends the Select Field. Please read that article to learn how to add options to the multiselect field.
As shown in the screenshot in the beginning of this article, the multiselect field supports two input types:
- A multiselect select, as indicated in the name of the field, is the default input type.
-
Checkboxes will use
<input type="checkbox" />
-es for each option and is more suitable for fields with few options.
In PHP, you can use the set_input_type( $type)
method of the field. The supported options for $type are "multiselect" (defult) and "checkboxes".
Field::create( 'multiselect', 'modules' )
->set_input_type( 'checkboxes' )
->add_options(array(
'intro' => 'Intro',
'copy' => 'Copy',
'related_articles' => 'Related articles'
))
<?php
$modules = get_value( 'modules' );
if( in_array( 'intro', $modules ) ) { ?>
<!-- Intro -->
<?php }
if( in_array( 'copy', $modules ) ) { ?>
<!-- Copy -->
<?php }
if( in_array( 'related_articles', $modules ) ) { ?>
<!-- Related articles -->
<?php }
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials