PHPackages                             jeffreyvanrossum/wp-meta-box - 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. jeffreyvanrossum/wp-meta-box

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jeffreyvanrossum/wp-meta-box
============================

Handy package to make creating WordPress meta boxes a breeze.

0.6.0(1y ago)6393MITPHPPHP ^7.4|^8.0

Since Dec 6Pushed 1y ago3 watchersCompare

[ Source](https://github.com/jeffreyvr/wp-meta-box)[ Packagist](https://packagist.org/packages/jeffreyvanrossum/wp-meta-box)[ RSS](/packages/jeffreyvanrossum-wp-meta-box/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (12)Used By (0)

[![vanrossum.dev Logo](https://raw.githubusercontent.com/jeffreyvr/vanrossum.dev-art/main/logo.svg)](https://vanrossum.dev)

[![Total Downloads](https://camo.githubusercontent.com/8fc89c5346ac326ca873a5b099427521e6b54af871a47da5fba9783f3d122857/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a65666672657976616e726f7373756d2f77702d6d6574612d626f78)](https://packagist.org/packages/jeffreyvanrossum/wp-meta-box)[![Latest Stable Version](https://camo.githubusercontent.com/bcb614a0615b739f54d60859745e2f1777a3543186b3cdfe1787b6097b71d4f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65666672657976616e726f7373756d2f77702d6d6574612d626f78)](https://packagist.org/packages/jeffreyvanrossum/wp-meta-box)[![License](https://camo.githubusercontent.com/0aa9fbdc50ba1e5abf10b873b6026dc04787f036cbec045d432bbb65426f3a00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a65666672657976616e726f7373756d2f77702d6d6574612d626f78)](https://packagist.org/packages/jeffreyvanrossum/wp-meta-box)

WP Meta Box
===========

[](#wp-meta-box)

This package aims to make it easier to create meta boxes for WordPress plugins.

> ⚠️ Untill the first stable release, the API is subject to change. Use at your own risk.

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

[](#installation)

```
composer require jeffreyvanrossum/wp-meta-box
```

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

```
use Jeffreyvr\WPMetaBox\WPMetaBox;

$meta_box = WPMetaBox::post('Post settings')
    ->set_post_type('post');

$meta_box->add_option('text', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'description' => __('Some additional description', 'textdomain')
]);

$meta_box->make();

// Or for taxonomies:
$meta_box = WPMetaBox::taxonomy('Taxonomy settings')
    ->set_taxonomies(['category']);
```

### Available types

[](#available-types)

- [Text](#text)
- [Date](#date)
- [Number](#number)
- [Textarea](#textarea)
- [Checkbox](#checkbox)
- [Choices (Radio Buttons)](#choices-radio-buttons)
- [Color](#color)
- [Select](#select)
- [Select2](#select2)
- [Media](#media)
- [Image](#image)
- [Code Editor](#code-editor)
- [WP Editor](#wp-editor)
- [Repeater](#repeater)

#### Text

[](#text)

```
$meta_box->add_option('text', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Date

[](#date)

```
$meta_box->add_option('date', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Number

[](#number)

```
$meta_box->add_option('number', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

You may also pass `min` and `max`.

#### Textarea

[](#textarea)

```
$meta_box->add_option('textarea', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Checkbox

[](#checkbox)

```
$meta_box->add_option('checkbox', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Choices (radio buttons)

[](#choices-radio-buttons)

```
$meta_box->add_option('checkbox', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'options' => [
        1 => 'option 1',
        2 => 'option 2'
    ]
]);
```

#### Color

[](#color)

```
$meta_box->add_option('color', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Select

[](#select)

```
$meta_box->add_option('select', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'options' => [
        1 => 'option 1',
        2 => 'option 2'
    ]
]);
```

You can allow multiple values too.

```
$meta_box->add_option('select', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'multiple' => true,
    'options' => [
        1 => 'option 1',
        2 => 'option 2'
    ]
]);
```

### Select2

[](#select2)

Select2 gives you a customizable select box with support for searching.

You can use `select2` the same way you use the regular `select`.

```
$meta_box->add_option('select2', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'options' => [
        1 => 'option 1',
        2 => 'option 2'
    ]
]);
```

If you would like to search the options through ajax, you can do this by defining two callbacks (or function names). One for fetching and filtering the options and one for getting the value callback.

The below example is using select2 to select a page.

```
$meta_box->add_option('select2', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'ajax' => [
        'value' => function($pageId) {
            return get_the_title($pageId) ?? null;
        },
        'action' => function() {
            $results = array_reduce(get_posts(['post_type' => 'page', 's' => $_GET['q']]), function($item, $page) {
                $item[$page->ID] = $page->post_title;

                return $item;
            }, []);

            echo json_encode($results);

            die();
        }
    ]
]);
```

You may allow multiple values by settings the `multiple` value in `config` to true. If you want to use the ajax functionality here, be sure to define value callback here as well.

```
$meta_box->add_option('select2', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain'),
    'multiple' => true,
    'ajax' => [
        'value' => function($ids) {
            foreach($ids as $id) {
                $titles[$id] = get_the_title($id) ?? $id;
            }
            return $titles ?? [];
        },
        'action' => function() {
            $results = array_reduce(get_posts(['post_type' => 'page', 's' => $_GET['q']]), function($item, $page) {
                $item[$page->ID] = $page->post_title;

                return $item;
            }, []);

            echo json_encode($results);

            die();
        }
    ]
]);
```

You can pass anything you'd like to the select2 configuration using `config`, the exception being the ajax part of the configuration.

A list of options can be found [here](https://select2.org/configuration/options-api).

The Select2 that comes with the package is loaded from the Cloudflare CDN. You can overwrite this using the `wmb_select2_assets` filter hook.

#### Media

[](#media)

```
$meta_box->add_option('media', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Image

[](#image)

```
$meta_box->add_option('image', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### Code editor

[](#code-editor)

```
$meta_box->add_option('code-editor', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

#### WP Editor

[](#wp-editor)

```
$meta_box->add_option('wp-editor', [
    'name' => 'name_of_option',
    'label' => __('Label of option', 'textdomain')
]);
```

You can provide a `config` array to customize the editor. For more information on this config check out the [wp.editor documentation](https://codex.wordpress.org/Javascript_Reference/wp.editor).

#### Repeater

[](#repeater)

Example of a gallery using the repeater option:

```
$meta_box->add_option('repeater', [
    'name' => 'gallery',
    'label' => __('Gallery', 'textdomain'),
])->add_repeater_option('image', [
    'name' => 'image',
    'label' => __('Image', 'textdomain'),
]);
```

### Sanitize

[](#sanitize)

If you want to sanitize the values of the input, you can pass a sanitize callback.

For example:

```
$meta_box->add_option('number', [
    'name' => 'some_number',
    'label' => __('Some number', 'textdomain'),
    'description' => __('Must be positive', 'textdomain'),
    'min' => 0,
    'max' => 10,
    'sanitize' => function($value) {
        return abs($value);
    }
]);
```

Contributors
------------

[](#contributors)

- [Jeffrey van Rossum](https://github.com/jeffreyvr)
- [All contributors](https://github.com/jeffreyvr/wp-meta-box/graphs/contributors)

License
-------

[](#license)

MIT. Please see the [License File](/LICENSE) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance40

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~54 days

Recently: every ~99 days

Total

9

Last Release

506d ago

PHP version history (2 changes)0.1.0PHP ^7.2|^8.0

0.2.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/66ca71465f93459010e10f39821b541f1c00c61233c48bcda0cea8a8d6fb6988?d=identicon)[jeffreyvr](/maintainers/jeffreyvr)

---

Top Contributors

[![jeffreyvr](https://avatars.githubusercontent.com/u/9550079?v=4)](https://github.com/jeffreyvr "jeffreyvr (50 commits)")

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jeffreyvanrossum-wp-meta-box/health.svg)

```
[![Health](https://phpackages.com/badges/jeffreyvanrossum-wp-meta-box/health.svg)](https://phpackages.com/packages/jeffreyvanrossum-wp-meta-box)
```

###  Alternatives

[ashallendesign/redactable-models

A Laravel package for easily redacting model data.

1143.4k](/packages/ashallendesign-redactable-models)[byrokrat/banking

Data types for accounts in the swedish banking system

1395.6k6](/packages/byrokrat-banking)[machy8/webloader

Simple, easy to use, php bundler for javascript and css

1934.2k3](/packages/machy8-webloader)[tobimori/kirby-tailwind-merge

Tailwind Merge for Kirby CMS

276.3k](/packages/tobimori-kirby-tailwind-merge)[imarc/craft-sass

A Craft plugin that compiles SASS on the server as needed.

145.8k](/packages/imarc-craft-sass)

PHPackages © 2026

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