1
嘿傢伙我有一個可怕的問題,基本上我想創建一個名爲「sermon_series」,我可以鏈接圖像的自定義分類中的元字段。一切都已創建,但它不會保存。我試過很多其他的代碼變體,但都沒有工作。感謝您的幫助,繼承人我的代碼:WordPress的自定義分類標準額外的領域不存儲
<?php
//add extra fields to custom taxonomy edit form callback function
function extra_tax_fields($tag) {
//check for existing taxonomy meta for term ID
$t_id = $tag->term_id;
$term_meta = get_option("taxonomy_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="cat_Image_url"><?php _e('Category Image Url'); ?></label></th>
<td>
<input type="text" name="term_meta[img]" id="term_meta[img]" size="3" style="width:60%;" value="<?php echo $term_meta['img'] ? $term_meta['img'] : ''; ?>"><br />
<span class="description"><?php _e('Image for Term: use full url with http://'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra1"><?php _e('extra field'); ?></label></th>
<td>
<input type="text" name="term_meta[extra1]" id="term_meta[extra1]" size="25" style="width:60%;" value="<?php echo $term_meta['extra1'] ? $term_meta['extra1'] : ''; ?>"><br />
<span class="description"><?php _e('extra field'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra2"><?php _e('extra field'); ?></label></th>
<td>
<input type="text" name="term_meta[extra2]" id="term_meta[extra2]" size="25" style="width:60%;" value="<?php echo $term_meta['extra2'] ? $term_meta['extra2'] : ''; ?>"><br />
<span class="description"><?php _e('extra field'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra3"><?php _e('extra field'); ?></label></th>
<td>
<textarea name="term_meta[extra3]" id="term_meta[extra3]" style="width:60%;"><?php echo $term_meta['extra3'] ? $term_meta['extra3'] : ''; ?></textarea><br />
<span class="description"><?php _e('extra field'); ?></span>
</td>
</tr>
<?php
}
// save extra taxonomy fields callback function
function save_extra_taxonomy_fields($term_id) {
if (isset($_POST['term_meta'])) {
$t_id = $term_id;
$term_meta = get_option("taxonomy_$t_id");
$cat_keys = array_keys($_POST['term_meta']);
foreach ($cat_keys as $key){
if (isset($_POST['term_meta'][$key])){
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
//save the option array
update_option("taxonomy_$t_id", $term_meta);
}
}
add_action('sermon_series_edit_form_fields', 'extra_tax_fields', 10, 2);
add_action('edited_sermon_series', 'save_extra_fields_callback', 10, 2);
?>
你有這個工作嗎?我現在正在遇到一模一樣的問題! – Jeremy 2013-03-15 19:39:16