Created
March 19, 2021 22:59
-
-
Save cagriuckan/34b1a699c4cd103cbef8585ad0aa0f61 to your computer and use it in GitHub Desktop.
Wordpress Kategori Sayfasına Özel Alan Kullanımına Örnek
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', '' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kategori sayfalarında kullanımı ise şöyledir;
<?php echo get_term_meta(get_query_var('cat'), 'category-custom-description', true); ?>