Fields ###### Plugin is defining custom meta fields. All fields are implemented by using third party `CMB2 plugin`_. .. _`CMB2 plugin`: https://wordpress.org/plugins/cmb2/ * `Official documentation`_ * `Available field types`_ * `Bringing fields on the front end`_ .. _`Official documentation`: https://github.com/webdevstudios/CMB2/wiki .. _`Available field types`: https://github.com/WebDevStudios/CMB2/wiki/Field-Types .. _`Bringing fields on the front end`: http://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/ Fields definition are stored in ``includes/post-types/class-horizon-post-type-POST_TYPE_NAME.php`` files. Each post type is using own ``fields()`` static method for its fields definition. Using predefined metaboxes ========================== If you want to add :doc:`built in metaboxes ` to a post type, you can use ``Horizon_Post_Types::add_metabox()`` method (see example below). .. code-block:: php :linenos: :emphasize-lines: 24 add_action( 'cmb2_init', 'doctor_fields' ); function doctor_fields() { Horizon_Post_Types::add_metabox( 'doctor', array( 'general', 'banner', 'gallery', 'video', 'location', 'price', 'contact', 'flags', 'listing_category' ) ); } Remove predefined metabox ========================= If you want to remove :doc:`built in metabox ` from a listing post type, you can use ``Horizon_Post_Types::remove_metabox()`` method. In example below we removed *"Video"* metabox from *"Doctor"* listing type. .. code-block:: php :linenos: :emphasize-lines: 24 add_action( 'cmb2_init', 'remove_metabox', 11 ); function remove_metabox() { Horizon_Post_Types::remove_metabox( 'doctor', array( 'video', ) ); } Create new field ================ It predefined metaboxes do'nt meet your requirements, you can create your own fields. Below is a small example how to add new *"Fax"* field into existing *"Contact"* metabox of *"Doctor"* listing type. .. code-block:: php :linenos: add_action( 'cmb2_init', 'custom_fields', 11 ); function custom_fields( ) { $contact_metabox = CMB2_Boxes::get( HORIZON_LISTING_PREFIX . 'doctor_contact' ); if ( ! empty( $contact_metabox ) ) { $contact_metabox->add_field( array( 'id' => HORIZON_LISTING_PREFIX . 'doctor_fax', 'name' => __( 'Fax', 'domain' ), 'type' => 'text' ) ); } } .. note :: If you want to add field on the specific position, set second argument of ``add_field()`` function. Creating metabox ================ Adding new metaboxes is quite similar as extending them. We will define all metabox information instead of just adding new field. Below you can see an example how to define new *"Details"* metabox with *"Salary"* field for *"Doctor"* listing type. This is just a sample, for more information check CMB2 official documentation. .. code-block:: php :linenos: add_action( 'cmb2_init', 'custom_metabox' ); function custom_metabox() { $details_metabox = new_cmb2_box( array( 'id' => HORIZON_LISTING_PREFIX . 'doctor_details', 'title' => __( 'Details', 'domain' ), 'object_types' => array( 'doctor' ), 'context' => 'normal', 'priority' => 'high', 'skip' => false ) ); $details_metabox->add_field( array( 'name' => __( 'Salary', 'domain' ), 'id' => HORIZON_LISTING_PREFIX . 'doctor_salary', 'type' => 'text', 'attributes' => array( 'type' => 'number', 'min' => 0 ) ) ); } .. note:: All metabox fields are visible in listing detail attributes by default. To avoid that, set ``skip`` field argument to ``true``.