PHPackages                             cehojac/cmb-field-select2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cehojac/cmb-field-select2

ActiveWordpress-plugin[Utility &amp; Helpers](/categories/utility)

cehojac/cmb-field-select2
=========================

Select2 field type for CMB2

v3.0.4.1(5y ago)02.2k↓33.3%GPL-2.0+PHP

Since May 25Pushed 5y agoCompare

[ Source](https://github.com/cehojac/cmb-field-select2)[ Packagist](https://packagist.org/packages/cehojac/cmb-field-select2)[ Docs](https://github.com/cehojac/cmb-field-select2)[ RSS](/packages/cehojac-cmb-field-select2/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (7)Used By (0)

CMB2 Field Type: Select2
========================

[](#cmb2-field-type-select2)

Description
-----------

[](#description)

[Select2](https://select2.github.io/) field type for [CMB2](https://github.com/WebDevStudios/CMB2 "Custom Metaboxes and Fields for WordPress 2").

This plugin gives you two additional field types based on Select2:

1. The `pw_select` field acts much like the default `select` field. However, it adds typeahead-style search allowing you to quickly make a selection from a large list
2. The `pw_multiselect` field allows you to select multiple values with typeahead-style search. The values can be dragged and dropped to reorder new items
3. The `pw_select_taxonomy` and
4. The `pw_multiselect_taxonomy`

Installation
------------

[](#installation)

You can install this field type as you would a WordPress plugin:

1. Download the plugin
2. Place the plugin folder in your `/wp-content/plugins/` directory
3. Activate the plugin in the Plugin dashboard

Alternatively, you can include this field type within your plugin/theme. The path to front end assets (JS/CSS) can be filtered using `pw_cmb2_field_select2_asset_path`. See an example where we [load assets from the current active theme](http://link.from.pw/pw_cmb2_field_select2_asset_path).

Usage
-----

[](#usage)

`pw_select` - Select box with with typeahead-style search. Example:

```
$cmb->add_field( array(
	'name'    => 'Cooking time',
	'id'      => $prefix . 'cooking_time',
	'desc'    => 'Cooking time',
	'type'    => 'pw_select',
	'options' => array(
		'5'  => '5 minutes',
		'10' => '10 minutes',
		'30' => 'Half an hour',
		'60' => '1 hour',
	),
) );
```

`pw_multiselect` - Multi-value select box with drag and drop reordering. Example:

```
$cmb->add_field( array(
	'name'    => 'Ingredients',
	'id'      => $prefix . 'ingredients',
	'desc'    => 'Select ingredients. Drag to reorder.',
	'type'    => 'pw_multiselect',
	'options' => array(
		'flour'  => 'Flour',
		'salt'   => 'Salt',
		'eggs'   => 'Eggs',
		'milk'   => 'Milk',
		'butter' => 'Butter',
	),
) );
```

### Placeholder

[](#placeholder)

You can specify placeholder text through the attributes array. Example:

```
$cmb->add_field( array(
	'name'    => 'Ingredients',
	'id'      => $prefix . 'ingredients',
	'desc'    => 'Select this recipes ingredients.',
	'type'    => 'pw_multiselect',
	'options' => array(
		'flour'  => 'Flour',
		'salt'   => 'Salt',
		'eggs'   => 'Eggs',
		'milk'   => 'Milk',
		'butter' => 'Butter',
	),
	'attributes' => array(
		'placeholder' => 'Select ingredients. Drag to reorder'
	),
) );
```

### Custom Select2 configuration and overriding default configuration options

[](#custom-select2-configuration-and-overriding-default-configuration-options)

You can define Select2 configuration options using HTML5 `data-*` attributes. It's worth reading up on the [available options](https://select2.github.io/options.html#data-attributes) over on the Select2 website. Example:

```
$cmb->add_field( array(
	'name'    => 'Ingredients',
	'id'      => $prefix . 'ingredients',
	'desc'    => 'Select ingredients. Drag to reorder.',
	'type'    => 'pw_multiselect',
	'options' => array(
		'flour'  => 'Flour',
		'salt'   => 'Salt',
		'eggs'   => 'Eggs',
		'milk'   => 'Milk',
		'butter' => 'Butter',
	),
	'attributes' => array(
		'data-maximum-selection-length' => '2',
	),
) );
```

Helper functions
----------------

[](#helper-functions)

You may want to populate the options array dynamically. Common use cases include listing out posts and taxonomy terms. I've written a number of generic helper functions which can be used to return a CMB2 style array for both [posts](http://link.from.pw/1PkJmWc) and [terms](http://link.from.pw/1TDArjR).

Limitations/known issues
------------------------

[](#limitationsknown-issues)

If you’d like to help out, pull requests are more than welcome!

- This field does not work well as a repeatable field within a repeatable group.
- Yoast SEO also loads Select2. Currently a version behind, there is an issue with the previous version of Select2 and it's ability to position the dropdown relative to the field.

Screenshots
-----------

[](#screenshots)

### Select box

[](#select-box)

[![Image](screenshot-1.png?raw=true)](screenshot-1.png?raw=true)

### Multi-value select box

[](#multi-value-select-box)

[![Image](screenshot-2.png?raw=true)](screenshot-2.png?raw=true)

[![Image](screenshot-3.png?raw=true)](screenshot-3.png?raw=true)

[![Image](screenshot-4.png?raw=true)](screenshot-4.png?raw=true)

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~311 days

Recently: every ~366 days

Total

6

Last Release

2078d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f47eb02703b705a42d3f4a51233a2038edc1deb9115b563628a35fac40d72150?d=identicon)[cehojac](/maintainers/cehojac)

---

Top Contributors

[![mustardBees](https://avatars.githubusercontent.com/u/1236314?v=4)](https://github.com/mustardBees "mustardBees (36 commits)")[![cehojac](https://avatars.githubusercontent.com/u/1319696?v=4)](https://github.com/cehojac "cehojac (8 commits)")[![jtsternberg](https://avatars.githubusercontent.com/u/1098900?v=4)](https://github.com/jtsternberg "jtsternberg (4 commits)")[![gyrus](https://avatars.githubusercontent.com/u/609161?v=4)](https://github.com/gyrus "gyrus (2 commits)")[![pasqualevitiello](https://avatars.githubusercontent.com/u/2683512?v=4)](https://github.com/pasqualevitiello "pasqualevitiello (2 commits)")[![franckmaurin](https://avatars.githubusercontent.com/u/217914?v=4)](https://github.com/franckmaurin "franckmaurin (1 commits)")[![richardtape](https://avatars.githubusercontent.com/u/116946?v=4)](https://github.com/richardtape "richardtape (1 commits)")

---

Tags

pluginwordpress

### Embed Badge

![Health badge](/badges/cehojac-cmb-field-select2/health.svg)

```
[![Health](https://phpackages.com/badges/cehojac-cmb-field-select2/health.svg)](https://phpackages.com/packages/cehojac-cmb-field-select2)
```

###  Alternatives

[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)[webdevstudios/cmb2-attached-posts

Custom field for CMB2 for creating post relationships.

13565.5k](/packages/webdevstudios-cmb2-attached-posts)[appsero/client

Appsero Client

25431.7k8](/packages/appsero-client)[boxybird/inertia-wordpress

The WordPress adapter for Inertia.js

1827.4k](/packages/boxybird-inertia-wordpress)[iceicetimmy/acf-post-type-selector

Post type selector for Advanced Custom Fields.

559.0k](/packages/iceicetimmy-acf-post-type-selector)[alexis-magina/cmb2-field-post-search-ajax

CMB2 field type to attach posts to each others. Search with Ajax.

3913.4k1](/packages/alexis-magina-cmb2-field-post-search-ajax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
