Skip to content

Instantly share code, notes, and snippets.

@rodrigoea
Last active August 29, 2015 14:06
Show Gist options
  • Save rodrigoea/2bd1a82f3c5ba767edac to your computer and use it in GitHub Desktop.
Save rodrigoea/2bd1a82f3c5ba767edac to your computer and use it in GitHub Desktop.
Dynamic Custom Fields With Custom Metaboxes - Wordpress
//download
$meta_boxes[] = array(
'id' => 'meta_marcas_downloads',
'title' => 'Downloads',
'pages' => array( 'qd_marcas' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'id' => $prefix . 'marcas_downloads',
'type' => 'group',
'description' => __( 'Itens de download', 'cmb' ),
'options' => array(
'group_title' => __( 'Arquivo {#}', 'cmb' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'Adicionar outro item', 'cmb' ),
'remove_button' => __( 'Remover item', 'cmb' ),
'sortable' => true, // beta
),
// Fields array works the same, except id's only need to be unique for this group. Prefix is not needed.
'fields' => array(
array(
'name' => 'Título do arquivo',
'description' => '',
'id' => $prefix . 'marcas_downloads_title',
'type' => 'text_medium',
),
array(
'name' => 'Upload do arquivo',
'desc' => '',
'id' => $prefix . 'marcas_download_file',
'type' => 'file',
'save_id' => true
),
),
),
),
);
//downloads
$entries_downloads = get_post_meta( get_the_ID(), 'qd_marcas_downloads', true );
foreach( (array) $entries_downloads as $key => $entry ):
$marcas_downloads_title = $entry['qd_marcas_downloads_title'];
$marcas_download_file = $entry['qd_marcas_download_file'];
endforeach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment