Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Custom Meta Boxes

DomagojGojak edited this page Dec 4, 2014 · 2 revisions

OmniBuilder provides OmniBuilder\Custom_Meta_Box class that makes custom meta box implementation feel far more natural. Adding meta boxes to the custom post type(s) is as easy as setting up a array of Custom_Meta_Box instances that is being passed as a second argument during the new OmniBuilder\Custom_Post_Type instantiation.

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'informations', 'Informations' ),
	new Custom_Meta_Box( 'related', 'Related' )
) );

Once you add one (or more) custom meta boxes you will want to add some fields to it. Currently, OmniBuilder has 7 fields in it's library and those are:

Text

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Text;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'informations', 'Informations', array(
		new Text( 'location', array(
			'label' => 'Location:'
		) ),
		new Text( 'year', array(
			'label' => 'Year:'
		) )
	) )
) );

Textarea

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Textarea;

$book = new Custom_Post_Type( 'book', array(
	new Custom_Meta_Box( 'informations', 'Informations', array(
		new Textarea( 'about_author', array(
			'label' => 'About the author:'
		) ),
		new Textarea( 'about_book', array(
			'label' => 'About the book:'
		) )
	) )
) );

Fieldset

Fieldset is a field that acts as a container around one or more child fields. Fieldsets are mostly used for styling purposes and seperation of fields with the same name in order to avoid collision.

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Fieldset;
use OmniBuilder\Field\Textarea;

$book = new Custom_Post_Type( 'book', array(
    new Custom_Meta_Box( 'informations', 'Informations', array(
        new Fieldset( 'author', array(), array(
            new Textarea( 'about', array(
                'label' => 'About the author:'
            ) )
        ) ),
        new Fieldset( 'book', array(), array(
            new Textarea( 'about', array(
                'label' => 'About the book:'
            ) )
        ) )
    ) )
) );

Collection

Collection field is used to render collection (array) of child fields, fieldsets or even child collections. Collection enables you to dynamicly add, delete, update and sort collection entries (rows).

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Collection;
use OmniBuilder\Field\Text;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'informations', 'Informations', array(
		new Collection( 'specifications', array(), array(
			new Text( 'specification', array(
				'label' => 'Specification:'
			) ),
			new Text( 'value', array(
				'label' => 'Value:'
			) )
		) )
	) )
) );

Checkbox

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Checkbox;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'options', 'Options', array(
		new Checkbox( 'featured', array(
			'label' => 'Mark as featured'
		) )
	) )
) );

Radio

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Radio;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'options', 'Options', array(
		new Radio( 'featured', array(
			'label' => 'Mark as featured:',
			'choices' => array(
				'yes' => 'Yes',
				'no' => 'No'
			)
		) )
	) )
) );

Select

use OmniBuilder\Custom_Post_Type;
use OmniBuilder\Custom_Meta_Box;
use OmniBuilder\Field\Select;

$project = new Custom_Post_Type( 'project', array(
	new Custom_Meta_Box( 'options', 'Options', array(
		new Select( 'location', array(
			'label' => 'Location:',
			'choices' => array(
				'header' => 'Header',
				'sidebar' => 'Sidebar',
				'footer' => 'Footer',
			)
		) )
	) )
) );
Clone this wiki locally