Criar/Pegar Metaboxes cmb2
add_action( 'cmb2_init', 'foundation_q_register_metaboxes' );
function foundation_q_register_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = 'qd_';
/* *
* Group metaboxes comum
*/
$page_solution = new_cmb2_box( array(
'id' => $prefix . 'solution_options',
'title' => 'Informações Adicionais',
'object_types' => array( 'page', ), // Post type
'show_on' => array( 'key' => 'page-template', 'value' => 'page-model-inner-solutions.php' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'cmb_styles' => true, // false to disable the CMB stylesheet
'closed' => false, // true to keep the metabox closed by default
// 'show_on_cb' => 'yourprefix_show_if_front_page', // function should return a bool value
));
$page_solution->add_field( array(
'name' => 'Cor',
'desc' => 'Selecione a cor característica para a solução.',
'id' => $prefix . 'solution_colorpicker',
'type' => 'colorpicker',
'default' => '#e00109',
));
$page_solution->add_field( array(
'name' => 'Ícone',
'desc' => 'Faça upload do ícone que ficará no topo da interna da solução.',
'id' => $prefix . 'solution_image',
'type' => 'file',
'preview_size' => array( 50, 50 ), // Default: array( 50, 50 )
));
$page_solution->add_field( array(
'name' => 'Cabeçalho',
'desc' => 'Faça upload da imagem que ficará como background do topo da interna da solução.',
'id' => $prefix . 'solution_top_background',
'type' => 'file',
));
/* *
* Group metaboxes com opecao de add ou remover
*/
$page_solution_group_cmb2 = new_cmb2_box( array(
'id' => $prefix . 'solution_group_cmb2',
'title' => 'Características da Solução',
'object_types' => array( 'page', ), // Post type
'show_on' => array( 'key' => 'page-template', 'value' => 'page-model-inner-solutions.php' ),
));
$page_solution_group = $page_solution_group_cmb2->add_field( array(
'id' => $prefix . 'solution_group',
'type' => 'group',
'description' => '',
'options' => array(
'group_title' => 'Característica {#}', // {#} gets replaced by row number
'add_button' => 'Adicionar característica',
'remove_button' => 'Remover característica',
'sortable' => true, // beta
),
));
$page_solution_group_cmb2->add_group_field( $page_solution_group, array(
'name' => 'Título da característica',
'id' => 'title',
'type' => 'text',
// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
));
$page_solution_group_cmb2->add_group_field( $page_solution_group, array(
'name' => 'Descrição da característica',
'description' => '',
'id' => 'description',
'type' => 'textarea_small',
));
$page_solution_group_cmb2->add_group_field( $page_solution_group, array(
'name' => 'Imagem',
'description' => '',
'id' => 'image',
'type' => 'file',
));
}