Skip to content

Instantly share code, notes, and snippets.

@cagriuckan
Created March 19, 2021 22:59
Show Gist options
  • Save cagriuckan/34b1a699c4cd103cbef8585ad0aa0f61 to your computer and use it in GitHub Desktop.
Save cagriuckan/34b1a699c4cd103cbef8585ad0aa0f61 to your computer and use it in GitHub Desktop.
Wordpress Kategori Sayfasına Özel Alan Kullanımına Örnek
<?php
// Oluşturma Sayfasına Ekle
add_action( 'category_add_form_fields', 'add_category_field', 10, 2 );
function add_category_field( $taxonomy ) { ?>
<div class="form-field term-group">
<label for="category-custom-description">Açıklama</label>
<textarea rows="5" id="category-custom-description" name="category-custom-description"></textarea>
</div>
<?php }
// Oluşturma Sayfasında Güncelleme
add_action( 'created_category', 'save_category_field', 10, 2 );
function save_category_field ( $term_id, $tt_id ) {
if( isset( $_POST['category-custom-description'] ) && '' !== $_POST['category-custom-description'] ){
$posts = $_POST['category-custom-description'];
add_term_meta( $term_id, 'category-custom-description', $posts, true );
}
}
// Düzenleme Sayfasına Ekle
add_action( 'category_edit_form_fields', 'edit_category_fields', 10, 2 );
function edit_category_fields($term, $taxonomy ) {
$description = get_term_meta( $term->term_id, 'category-custom-description', true );
?>
<tr class="form-field">
<th scope="row"><label for="category-custom-description">Açıklama</label></th>
<td>
<textarea row="5" name="category-custom-description" id="category-custom-description"><?php echo $description; ?></textarea>
</td>
</tr>
<?php }
// Düzenleme Sayfasında Güncelleme
add_action( 'edited_category', 'updated_category_fields', 10, 2 );
function updated_category_fields ( $term_id, $tt_id ) {
if( isset( $_POST['category-custom-description'] ) && '' !== $_POST['category-custom-description'] ){
$description = $_POST['category-custom-description'];
update_term_meta ( $term_id, 'category-custom-description', $description );
} else {
update_term_meta ( $term_id, 'category-custom-description', '' );
}
}
@cagriuckan
Copy link
Author

Kategori sayfalarında kullanımı ise şöyledir;

<?php echo get_term_meta(get_query_var('cat'), 'category-custom-description', true); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment