2012-02-28 11 views
1

私は恐ろしい問題を抱えています。基本的に私は画像をリンクできる「sermon_series」というタイトルのカスタムタクソノミーにメタフィールドを作成します。すべてが作成されますが、保存されません。私はコードの他の多くのバリエーションを試したが、誰も働いていない。あなたの助けてくれてありがとう私のコード: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 - > "Edit Sermon Series"の編集を行います。

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

は、初めて新しい説教シリーズを作成するときに保存されます - > "説教シリーズを追加"。コードには必ず両方を含めるようにしてください。

関連する問題