Standardowa funkcja w functions.php
function custom_fields(){}
add_action('cmb2_init', 'custom_fields');
Normalne
$field = get_post_meta( get_the_id(), 'field_name', true );
Meta box zależny od szablonu:
$page = new_cmb2_box( array( 'id' => 'home01', 'title' => esc_html__( 'Sekcja 01', 'cmb2' ), 'object_types' => array( 'page' ), 'show_on' => array( 'key' => 'page-template', 'value' => 'templates/template-home.php' ), ) );
Haki
WYSIWYG z CMB2 nie dopuszcza np iframe’ów. Trzeba wyłączyć mu tą opcję np poprzez całkowite wyłączenie sanitization
$post_content_group->add_group_field( $post_content_repeat, array(
'name' => esc_html__( '', 'cmb2' ),
'id' => 'post_content_wysiwyg',
'type' => 'wysiwyg',
'options' => array(
'textarea_rows' => 15,
'editor_class' => 'cmb2-qtranslate',
),
'sanitization_cb' => false,
) );
Shortcodes w WYSIWYG z cmb2 (na froncie trzeba przepuścić przez filtr „the content”)
$firstText = apply_filters( 'the_content', get_post_meta( get_the_id(), $prefix . 'lp_text', true ) );
Paginacja file list
Uzupełnianie selecta za pomocą wp_query
$labs = new WP_Query(array(
’posts_per_page’ => -1,
’post_type’ => 'page’,
’meta_key’ =>’_wp_page_template’,
’meta_value’ => 'templates/template-lab.php’,
));
//echo '<pre>’;
// print_r($labs->posts);
//echo '</pre>’;
$aLabs = array();
$aLabs[’administracja’] = 'Administracja’;
$aLabs[’wydawnictwo’] = 'Wydawnictwo’;
foreach ($labs->posts as $key => $val) {
$title = $val->post_title;
if (strpos($title, '[:en]’)) {
$pl_end = strpos($title, '[:en]’);
$pl_length = $pl_end – 5;
$title = substr($title, 5, $pl_length);
} else if (strpos($title, '[:]’)) {
$pl_end = strpos($title, '[:]’);
$pl_length = $pl_end – 5;
$title = substr($title, 5, $pl_length);
}
$aLabs[$val->ID] = $title;
}
restore_current_blog();
$people_fields->add_field( array(
’name’ => __(’Pracownia’, 'cmb2′),
’id’ => 'lab_select’,
’type’ => 'select’,
’show_option_none’ => true,
’options’ => $aLabs,
));