Fields

Plugin si defining custom meta fields. All fields are implemented by using third party CMB2 plugin. You can find it on wordpress.org/plugins/cmb2.

Fields definition are stored in includes/post-types/class-realia-post-type-POST_TYPE_NAME-.php files. Plugin is using fields() or fields_front() static methods for fields definition.

Exteding forms

Below is small example how to add new field. NOTE: If you want to add field on the specific position check an article on StackOverflow.

add_action( 'cmb2_meta_boxes', 'custom_fields' );

function custom_fields( array $metaboxes ) {
    $metaboxes[REALIA_PROPERTY_PREFIX . 'general']['fields'][] = array(
        'id'    => REALIA_PROPERTY_PREFIX . 'custom_field',
        'name'  => 'Field title',
        'type'  => 'text'
    );

    return $metaboxes;
}

Adding metaboxes

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 metabox for property. This is just sample and for more information check CMB2 official documentation.

add_action( 'cmb2_meta_boxes', 'custom_metabox' );

function custom_metabox( array $metaboxes ) {
    $metaboxes[REALIA_PROPERTY_PREFIX . 'custom_metabox'] = array(
        'id'                        => REALIA_PROPERTY_PREFIX . 'custom',
        'title'                     => 'Custom title',
        'object_types'              => array( 'property' ),
        'context'                   => 'normal',
        'priority'                  => 'high',
        'show_names'                => true,
        'fields'                    => array(
            array(
                'id'    => REALIA_PROPERTY_PREFIX . 'custom_field',
                'name'  => 'Field title',
                'type'  => 'text'
            ),
        ),
    );

    return $metaboxes;
}