Skip to content
Carlos Moreira edited this page Jun 2, 2020 · 2 revisions

The meta parameter allows you to create one or multiple metaboxes associated with your Custom Post Type.

It should contain an array of metaboxes models. Simplified example:

'meta' => [
	'ts_info' => [
		'id'       => 'information_metabox',
		'title'    => __( 'Information', 'framework-demo' ),
		'context'   => 'side',
		'priority'  => 'high',
		'sections' => [
			'details' => [],
			'gallery' => [],
			'notes'   => [],
			],
		],
	],
	'ts_advanced' => [
		'id'       => 'advanced_metabox',
		'title'    => __( 'Advanced', 'framework-demo' ),
		'sections' => [
			'advanced' => [],
			],
		],
	],
],

The above code will add 2 metaboxes, the first one containing multiple sections and the second one just one section. When multiple sections are added they will display in tabs.

You can access their values the following way:

$info     = get_post_meta( $post_id, 'ts_info' );
$advanced = get_post_meta( $post_id, 'ts_advanced' );

Saltus uses the Codestar Framework to generate the metaboxes, so you can refer to their documentation for the available parameters for each metabox and each section of the metabox.

Fields

When declaring the fields, there's some particularities that should be mentioned. As already mentioned, we're using the Codestart Framework to generate the metaboxes, so all field types available in that framework can be used in a Saltus metabox model. However, when listing the fields in our model, we should have a reference id for each. Notice the example below:

	'fields' => [
		'paperback'  => [
			'title' => __( 'Paperback', 'framework-demo' ),
			'type'  => 'text',
			'desc'  => __( 'Number of pages', 'framework-demo' ),
		],
		'isbn'       => [
			'title' => __( 'ISBN', 'framework-demo' ),
			'type'  => 'text',
		],
		'desc'       => [
			'title' => __( 'Description', 'framework-demo' ),
			'type'  => 'textarea',
			'desc'  => __( 'Short description for this book', 'framework-demo' ),
		],
	],

You don't need to redeclare the id parameter for each field (but you can), as the reference id will be used.

A more complete example:

'meta'         => [
	// this is a metabox
	'ts_info' => [
		'id'       => 'information_metabox',
		'title'    => __( 'Information', 'framework-demo' ),
		'sections' => [
			// this is a section
			'details' => [
				'title'  => __( 'Details', 'framework-demo' ),
				'desc'   => __( 'Book details', 'framework-demo' ),
				'icon'   => 'fa fa-file-text-o',
				'fields' => [
					'paperback'  => [
						'title' => __( 'Paperback', 'framework-demo' ),
						'type'  => 'text',
						'desc'  => __( 'Number of pages', 'framework-demo' ),
					],
					'isbn'       => [
						'title' => __( 'ISBN', 'framework-demo' ),
						'type'  => 'text',
					],
					'desc'       => [
						'title' => __( 'Description', 'framework-demo' ),
						'type'  => 'textarea',
						'desc'  => __( 'Short description for this book', 'framework-demo' ),
					],
					'enabled'    => [
						'type'    => 'switcher',
						'title'   => __( 'Display more options', 'framework-demo' ),
						'default' => false,
					],
					'icon'       => [
						'title'      => __( 'Icon', 'framework-demo' ),
						'type'       => 'icon',
						'desc'       => __( 'Demo field', 'framework-demo' ),
						'dependency' => array( 'enabled', '==', 'true' ),
					],
					'icon_color' => [
						'title'      => __( 'Icon Color', 'framework-demo' ),
						'type'       => 'color',
						'desc'       => __( 'Social network icon colour', 'framework-demo' ),
						'dependency' => array( 'enabled', '==', 'true' ),
					],
				],
			],
			// this is a section
			'gallery' => [
				'title'  => __( 'Preview', 'framework-demo' ),
				'icon'   => 'fa fa-picture-o',
				'fields' => [
					'gallery' => [
						'title'    => __( 'Gallery', 'framework-demo' ),
						'type'     => 'gallery',
						'subtitle' => __( 'Images from the book.', 'framework-demo' ),
					],
				],
			],
			// this is a section
			'notes'   => [
				'title'  => __( 'Notes', 'framework-demo' ),
				'desc'   => __( 'Personal Notes', 'framework-demo' ),
				'icon'   => 'fa fa-sticky-note-o',
				'fields' => [
					'notes' => [
						'title'    => __( 'Notes', 'framework-demo' ),
						'type'     => 'wp_editor',
						'subtitle' => __( 'Personal notes', 'framework-demo' ),
					],
				],
			],
		],
	],
],

Clone this wiki locally