2012-02-28 6 views
1

안녕하세요 여러분, 저는 기본적으로 이미지를 연결할 수있는 "sermon_series"라는 제목의 맞춤 분류에 메타 필드를 만들고 싶습니다. 모든 것이 만들어 지지만 저장되지 않습니다. 나는 많은 다른 코드 변형을 시도했지만 아무도 효과가 없다. 도와 주셔서 감사합니다,를 heres 내 코드 :Wordpress Custom Taxonomy 여분의 필드가 저장되지 않습니다.

<?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); 
?> 
+0

이 작업을 수행 했습니까? 나는 똑같은 문제를 겪고있다! – Jeremy

답변

0

당신은 또한 새로운 분류 체계가 만들어 질 때의 후크가 필요합니다. > "편집 설교 시리즈"-

add_action('edited_sermon_series', 'save_extra_fields_callback', 10, 2); 

은 sermon_series의 편집을 처리합니다.

add_action('created_sermon_series', 'save_extra_fields_callback', 10, 2); 

은 처음으로 새로운 설교 시리즈 -> "설교 시리즈 추가"를 만들 때 저장됩니다. 두 코드 모두 코드에 포함하십시오.

관련 문제