PHP code example of vietfreshair / cpt
1. Go to this page and download the library: Download vietfreshair/cpt library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vietfreshair / cpt example snippets
$book = new Vietfreshair\CPT('book', 'Book', 'Books');
$song = new Vietfreshair\CPT(
'song',
'Song',
'Songs',
['menu_icon' => 'dashicons-format-audio']
);
$book->registerMetafields(
[
[
'id' => 'test_metabox',
'title' => __( 'Test Metabox', 'cmb2' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
// 'cmb_styles' => false, // false to disable the CMB stylesheet
// 'closed' => true, // Keep the metabox closed by default
'fields' => [
[
'name' => __( 'Website URL', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'url',
'type' => 'text_url',
],
[
'name' => __( 'Test Text Email', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'email',
'type' => 'text_email',
// 'repeatable' => true,
]
]
],
[
'id' => 'test_metabox_2',
'title' => __( 'Test Metabox', 'cmb2' ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
// 'cmb_styles' => false, // false to disable the CMB stylesheet
// 'closed' => true, // Keep the metabox closed by default
'fields' => [
[
'name' => __( 'Website URL', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'url',
'type' => 'text_url',
],
[
'name' => __( 'Test Text Email', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => 'email',
'type' => 'text_email',
// 'repeatable' => true,
]
]
]
]
);