Kategori sayfalarına ek açıklama alanı ekleyen şu kodları kullanıyordum ancak Woordpress'in
wp_editor(); özelliğini eklemek için düzenledim. Düzenledikten sonra metin editörü geldi ancak kodlar bozuldu ve artık düzgün çalışmıyor, hatanın nerede olduğunu da çözemedim.
Sorun şu, önceden kategori ID'si ile "bottom_description" olarak MSQL'e veriyi kaydediyordu. Şimdi ise Wordpres'in kategori açıklama alanı ile kodlar çakışıyor ve bu alana yazdıklarım ek alan gibi değil kategori açıklamasının alternatif düzenleme alanı olarak çalışıyor. Kaydetme işlemini düzgün hale nasıl getirebilirim?
Düzenleme öncesi:
/* Custom Field for Categories */
function dm_category_fields($term) {
if (current_filter() == 'category_edit_form_fields') {
$bottom_description = get_term_meta($term->term_id, 'bottom_description', true);
?>
<tr class="form-field">
<th valign="top" scope="row"><label>Sayfa Sonu Açıklaması</label></th>
<td>
<textarea class="large-text" cols="50" rows="10" id="term_fields[bottom_description]" name="term_fields[bottom_description]"><?php echo esc_textarea($bottom_description); ?></textarea><br/>
<span class="description">Kategori içeriğinin sonuna bir şeyler eklemek için. Shortcode destekler.</span>
</td>
</tr>
<?php
}
}
add_action('category_add_form_fields', 'dm_category_fields', 10, 2);
add_action('category_edit_form_fields', 'dm_category_fields', 10, 2);
function wcr_save_category_fields($term_id) {
if (!isset($_POST['term_fields'])) {
return;
}
foreach ($_POST['term_fields'] as $key => $value) {
update_term_meta($term_id, $key, $value);
}
}
add_action('edited_category', 'wcr_save_category_fields', 10, 2);
add_action('create_category', 'wcr_save_category_fields', 10, 2);Düzenleme Sonrası:
/* Custom Field for Categories */
function dm_category_fields($term) {
if (current_filter() == 'category_edit_form_fields') {
$bottom_description = get_term_meta($term->term_id, 'bottom_description', true);
$description_field = 'Description';
//Provide the settings arguments for the editor
$description_args = array( 'media_buttons' => true, 'textarea_rows' => 12, 'textarea_name' => 'description', 'editor_class' => 'description-editor widefat', 'wpautop' => false );
?>
<tr class="form-field">
<th valign="top" scope="row"><label>Sayfa Sonu Açıklaması</label></th>
<td>
<?php wp_editor( $bottom_description, $description_field, $description_args ); ?>
</td>
</tr>
<?php
}
}
add_action('category_add_form_fields', 'dm_category_fields', 10, 2);
add_action('category_edit_form_fields', 'dm_category_fields', 10, 2);
function wcr_save_category_fields($term_id) {
if (!isset($_POST['term_fields'])) {
return;
}
foreach ($_POST['term_fields'] as $key => $value) {
update_term_meta($term_id, $key, $value);
}
}
add_action('edited_category', 'wcr_save_category_fields', 10, 2);
add_action('create_category', 'wcr_save_category_fields', 10, 2);