Привет, ребята. У меня ужасная проблема, в основном я хочу создать метаполе в пользовательской таксономии под названием «sermon_series», где я могу связать изображение.Все создано, но это не спасет.Я пробовал много других вариантов кода, но ни один не работал.Спасибо за вашу помощь, вот мой код:
<?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);
?>