Skip to main content

Switcher

A dynamic meta type which lets you define multiple groups of meta where a user can select from a dropdown and fill out the necessary fields. A switcher takes all normal props, as well as inputs. Switchers can be nested.

Value

Returns any[][]

$value = json_decode(fx_get_meta('id'), true);
switch ($value['_type_']) {
case 'Banner':
$banner_title = $value['title'];
$banner_description = $value['description'];
break;
case 'Post':
$feature_post_id = $value['feature_post'];
break;
default:
break;
}

$title = $values['title'];
$description = $values['description'];
$image = $values['image'];

Example

$banner_inputs = [
'title' => [
'type' => 'textfield',
'title' => 'Title',
],
'description' => [
'type' => 'wp-editor',
'title' => 'Description',
],
];

$post_inputs = [
'feature_post' => [
'type' => 'select',
'title' => 'Featured Post',
'options' => 'post',
],
];

'id' => [
'type' => 'switcher',
'className' => 'my-class-name',
'inputs' => [
'Banner' => $banner_inputs,
'Post' => $post_inputs,
],
],

Props

className

Metabox class name

type: string

inputs

Meta inputs to render

type: object

defaultValue: {}

label

Type select input label

type: string

title

Metabox title

type: string