Skip to content

Instantly share code, notes, and snippets.

@RadGH
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RadGH/c4b3a2d43a36b9b2ac97 to your computer and use it in GitHub Desktop.
Save RadGH/c4b3a2d43a36b9b2ac97 to your computer and use it in GitHub Desktop.
Quick matadata group and field declaration for the Custom Metadata Manager plugin.
<?php
/*
Format:
array(
group_key => (
post_type = TYPES,
args = ARGS,
fields = FIELDS,
),
group_key => ...
)
Groups and fields are structured automatically.
*/
$custom_fields = array(
'download-meta' => array(
'post_type' => 'download',
'args' => array('label' => 'Download Information'),
'fields' => array(
'file' => array(
'label' => 'Downloadable File:',
'field_type' => 'upload',
),
'filename' => array(
'label' => 'Filename (Required, include extension):',
'field_type' => 'text',
),
),
),
'download-reqs' => array(
'post_type' => 'download',
'args' => array('label' => 'Download Requirements'),
'fields' => array(
'allow_anon' => array(
'label' => 'Allow anonymous/guest downloads',
'field_type' => 'checkbox',
),
),
),
);
foreach( $custom_fields as $group_id => $group ) {
x_add_metadata_group( $group_id, $group['post_type'], $group['args'] );
foreach( $group['fields'] as $key => $field ) {
$field['group'] = $group_id;
x_add_metadata_field( $key, $group['post_type'], $field );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment