En iyi yolu kategorileri süzmek veya el görüntülenen istediğiniz olanları tanımlamak sonra, editör penceresinde kendi meta kutusunu yapmaktır.
Kategorilerden bir dizisini almak için get_categories onlara bu diziden sonra sonra seçeneklerden bazıları kaldırmak istiyorsanız sadece unset, kategorilerin bir dizisini almak için işlev basit kullanımı wordpress 'dir.
Bu benim aslında bu kategoriyi seçmek için kod içerdiği kendi php dosyasına bağlı functions.php, ve sonra kaydederek yerleştirilen ne kısa bir özetidir.
Bu ilk özel düzenleme bölüm yapmak için nasıl gösterir.
add_action('admin_menu', 'custom_admin');
/* Adds a custom section to the "side" of the post edit screen */
function custom_admin() {
add_meta_box('category_selector', 'Settings', 'category_custom_box', 'post', 'side', 'low');
/* prints the custom field in the new custom post section */
function category_custom_box() {
//get post meta values
global $post;
//$currentCat gets the pages current category id
$currentCat = wp_get_post_categories($post->ID);
//Do your printing of the form here.
}
Ve sonra kategori, yeni bir işlev yapmak kaydetmek ve 'save_post' kanca eklemek için.
/* when the post is saved, save the custom data */
function save_postdata($post_id) {
// verify this with nonce because save_post can be triggered at other times
if (!wp_verify_nonce($_POST['customCategory_noncename'], 'customCategory')) return $post_id;
// do not save if this is an auto save routine
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
//get the category and set it
$custom_category = $_POST['custom_category'];
wp_set_post_categories($post_id, array($custom_category));
...
}
Nonce değer, oturum biri sadece form için bu ekleme yapmak için, eşzamanlılık kaçınarak, geçerli olduğunu kontrol etmek için sadece rasgele oluşturulmuş bir dizedir
<input type="hidden" name="customCategory_noncename" id="customCategory_noncename" value="<?= wp_create_nonce('customCategory'); ?>" />
Kod miktarı hakkında özür dilerim, ben ince poss kadar aşağı çalıştı.
Bu yardımcı olur umarım :)