Text
You can add fields to Posts, Users and Terms.
$box = register_cuztom_meta_box( $id, $post_type, array(
'fields' => array(
// Parameters
array(
'id' => '_data_example',
'type' => 'text',
'label' => __('Example'),
'description' => __('Field description'),
'explanation' => __('Field explanations'),
'default_value' => 'Default',
'options' => array(),
'args' => array(),
'repeatable' => false,
'show_admin_column' => false,
'admin_column_sortable' => false,
'admin_column_filter' => false,
),
// Text
array(
'id' => '_data_text_field',
'type' => 'text',
'label' => 'Field Label',
),
...
)
) );
id
(string) Set the ID of the field. Prefix with "_" to keep it hidden from builtin custom fields. ALL fields, including Bundles, Tabs and Accordions need an ID.
type
(string) Field type (e.g. textarea, select, radios)
label
(string) The label for the field
description
(string) Shown below the label
explanation
(string) Extra explanation. Shown below the field itself.
default_value
(string|array) Default value
options
(array) Field options, only used for select, radios and checkboxes
args
(array) Field specific args
repeatable
(boolean) Set the field to be repeatable. This makes it possible to add multiple value rows.
show_admin_column
(boolean) Show the field as a admin column in the post table
admin_column_sortable
(boolean) Make the admin column sortable
admin_column_filter
(boolean) Make the admin column filterable
Examples
Adding a field with sortable admin column
$box = new Cuztom_Meta_Box( $id, $title, $post_type, array(
array(
'id' => '_data_text_field'
'type' => 'text',
'label' => 'Field Label',
'show_admin_column' => true,
'admin_column_sortable' => true
),
...
) );
Updated over 7 years ago