Meta boxes

This configuration contains parameters that HivePress uses for registering the custom meta boxes. Each meta box is defined as an array of the following parameters:

  • title - the meta box title;

  • screen - an array of post types or taxonomy names (without the hp_ prefix) to display the meta box for;

  • fields - an array of meta box fields, each field must be defined as an array of the field parameters.

The code example below adds a new meta box with a single checkbox field to the back-end listing edit page. By default, the field value is saved to the post (or term) meta. To save the field value to one of the standard post (or term) fields, use the _alias parameter.

add_filter(
	'hivepress/v1/meta_boxes',
	function( $meta_boxes ) {
		$meta_boxes['custom_meta_box'] = [
			'title'  => 'Custom Meta Box',
			'screen' => 'listing',

			'fields' => [
				'custom_option' => [
					'label'  => 'Custom Option',
					'type'   => 'checkbox',
					'_order' => 123,
				],
			],
		];

		return $meta_boxes;
	}
);

In the same way, you can customize any of the available meta boxes or register a new one by adding an array with the meta box parameters. For example, the code below adds a new text field to the Listing Settings meta box.

add_filter(
	'hivepress/v1/meta_boxes/listing_settings',
	function( $meta_box ) {
		$meta_box['fields']['custom_field'] = [
			'label'  => 'Custom Field',
			'type'   => 'text',
			'_order' => 123,
		];

		return $meta_box;
	}
);

Last updated