Fields / Group

Read More: Fieldmanager_Group

A group is a set of one or more fields. This allows you to create e.g. one meta box with many fields in it, create repeatable or sortable sets of fields, create tabbed interfaces, and more.

By default, groups will store its children’s data in the same storage field (post meta, user meta, etc. depending on context) as serialized PHP. To store group children separately, seeĀ Storing Data Unserialized.

  1. Example 1: Basic Group

    add_action( 'fm_post_post', function() {
    	$fm = new Fieldmanager_Group( array(
    		'name' => 'demo-group',
    		'children' => array(
    			'field-one' => new Fieldmanager_TextField( 'First Field' ),
    			'field-two' => new Fieldmanager_TextField( 'Second Field' ),
    		),
    	) );
    	$fm->add_meta_box( 'Basic Group', array( 'post' ) );
    } );
  2. Example 2: Vertical Tabbed Group

    This example uses vertical tabs, but there is also an option for horizontal tabs. To use horizontal tabs instead, set 'tabbed' => 'horizontal'

    add_action( 'fm_post_post', function() {
    	$fm = new Fieldmanager_Group( array(
    		'name'           => 'tabbed_meta_fields',
    		'tabbed'         => 'vertical',
    		'children'       => array(
    			'tab-1' => new Fieldmanager_Group( array(
    				'label'          => 'First Tab',
    				'children'       => array(
    					'text' => new Fieldmanager_Textfield( 'Text Field' ),
    				)
    			) ),
    			'tab-2' => new Fieldmanager_Group( array(
    				'label'          => 'Second Tab',
    				'children'       => array(
    					'textarea' => new Fieldmanager_TextArea( 'TextArea' ),
    					'media'    => new Fieldmanager_Media( 'Media File' ),
    				)
    			) ),
    		)
    	) );
    	$fm->add_meta_box( 'Tabbed Group', 'post' );
    } );