Skip to content

Instantly share code, notes, and snippets.

@jbotte
Forked from LinzardMac/gist:dc99cb97c3ebe6b602b6
Created February 12, 2015 19:15
Show Gist options
  • Save jbotte/00bc46b07d94dab70ae4 to your computer and use it in GitHub Desktop.
Save jbotte/00bc46b07d94dab70ae4 to your computer and use it in GitHub Desktop.
$prefix = 'custom_';
$custom_meta_fields = array(
array(
'label' => 'Multi-Day',
'desc' => '',
'id' => $prefix.'multiday',
'type' => 'checkbox'
),
array(
'label' => 'Recurring',
'desc' => '',
'id' => $prefix.'recurring',
'type' => 'checkbox'
),
array(
'label'=> 'Free Admission? ',
'desc' => 'Check box if admission if free',
'id' => $prefix.'cost_free',
'type' => 'checkbox'
)
);
// Begin the field table and loop
echo '<table class="form-table">';
foreach ($custom_meta_fields as $field) {
$values='';
$meta='';
// get value of this field if it exists for this post
$values = get_post_meta($post->ID, $field['id'], true);
if (isset($values)){
$meta = $values;
}else{
$values = null;
}
// begin a table row with
echo '<tr>
<th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
<td>';
switch($field['type']) {
case 'checkbox':
echo '<input type="checkbox" name="'.$field['id'].'" class="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>
<label for="'.$field['id'].'">'.$field['desc'].'</label>';
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment