2014-09-01 4 views
0

데모 패키지에이 플러그인을 작성했지만 관리자 패널에서이 추가 필드가 표시되지 않는 이유는 무엇입니까? 내가 뭘 잘못 했니?metabox가있는 사용자 정의 유형이 추가 필드를 표시하지 않습니다

나는 자동차 맞춤 부품을 만들었고 거기에는 무게, 브랜드 (택 소노 미), 가격이라는 두 개의 추가 필드가 있어야합니다.

<?php 
/* 
Plugin Name: spare parts 
Plugin URI: http://wp.tutsplus.com/ 
Description: descr 
Version: 1.0 
Author: Mr.Who 
Author URI: http://wp.tutsplus.com/ 
License: GPLv2 
*/ 
add_action('init', 'spare_part_init'); 

function spare_part_init() 
    { 


    $args = array(
    'label' => __('Spare parts') , 
    'labels' => array(
     'edit_item' => __('Edit Part') , 
     'add_new_item' => __('Add New Part') , 
     'view_item' => __('View Part') , 
    ) , 
    'singular_label' => __('Spare part') , 
    'public' => true, 
    'show_ui' => true, 
    '_builtin' => false, 
    'capability_type' => 'post', 
    'hierarchical' => false, 
    'rewrite' => array(
     "slug" => "spare_parts" 
    ) , // формат ссылок 
    'supports' => array(
     'title', 
     'editor', 
     'thumbnail' 
    ) 
); 


    register_post_type('spare_parts', $args);  
    register_taxonomy('mtype', 'brand', array(
    'hierarchical' => true, 
    'label' => __('Brands') , 
    'singular_label' => __('Brand') , 
    'query_var' => 'mtype' 
)); 
    } 

add_action("admin_init", 'spare_parts_admin_init'); 

function spare_parts_admin_init() 
    { 
    add_meta_box("part-meta", "Description", part_options, 'part', 'normal', 'low'); 
    } 

function part_options() 
    { 
    global $post; 
    echo '<input type="hidden" name="part_noncename" id="part_noncename" value="' . wp_create_nonce('part') . '" />'; 
    $my_fields = array(
    'weight' => '', 
    'brand' => '', 
    'price' => '' 
); 
    foreach($my_fields as $key => $value) 
    { 
    $my_fields[$key] = get_post_meta($post->ID, 'part-' . $key, true); 
    } 

    echo '<strong>Weight</strong><br/><br/><input name="part-weight" size="60" value="' . $my_fields['weight'] . '" /><br/><br/>' . "\n"; 
    echo '<strong>Brand</strong><br/><br/><input name="part-brand" size="60" value="' . $my_fields['brand'] . '" /><br/><br/>' . "\n"; 
    echo '<strong>Price</strong><br/><br/><input name="part-price" size="60" value="' . $my_fields['price'] . '" /><br/><br/>' . "\n"; 
    } 

add_action('save_post', 'part_save', 1, 2); 

function part_save() 
    { 
    global $post; 
    $post_id = $post->ID; 
    if (!wp_verify_nonce($_POST['part_noncename'], 'part')) return $post_id; 
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; 
    $post_flag = 'x'; 
    if ($post->post_type == "part") 
    { 
    $my_fields = array(
     'weight' => '', 
     'brand' => '', 
     'price' => '' 
    ); 
    $post_flag = 'part'; 
    } 

    if ($post_flag != 'x') 
    { 
    foreach($my_fields as $k => $v) 
     { 
     $key = 'part-' . $post_flag . '-' . $k; 
     $value = @$_POST[$key]; 
     if (empty($value)) 
     { 
     delete_post_meta($post_id, $key); 
     continue; 
     } 

     if (!is_array($value)) 
     { 
     if (!update_post_meta($post_id, $key, $value)) 
      { 
      add_post_meta($post_id, $key, $value); 
      } 
     } 
     else 
     { 
     delete_post_meta($post_id, $key); 
     foreach($value as $entry) add_post_meta($post_id, $key, $entry); 
     } 
     } 
    } 
    } 

add_action("manage_parts_custom_column", "part_custom_columns"); 
add_filter("manage_edit-parts_columns", "part_columns"); 

function part_columns($columns) 
    { 
    $columns = array(
    "cb" => "<input type=\"checkbox\" />", 
    "title" => "Name", 
    "weight" => "Weight", 
    "brand" => "Brand", 
    "price" => "Price" 
); 
    return $columns; 
    } 

function part_custom_columns($column) 
    { 
    global $post; 
    if ("ID" == $column) echo $post->ID; 
    elseif ("title" == $column) echo $post->post_title; 
    elseif ("weight" == $column) 
    { 
    $oweight = get_post_meta($post->ID, 'part-weight', true); 
    echo '<a href="' . $oweight . '" target="_blank">' . $oweight . '</a>'; 
    } 
    elseif ("brand" == $column) 
    { 
    $obrand = get_post_meta($post->ID, 'part-brand', true); 
    echo $obrand . '</a>'; 
    } 
    elseif ("price" == $column) 
    { 
    $oprice = get_post_meta($post->ID, 'part-price', true); 
    echo $oprice . '</a>'; 
    } 
    } 

?> 

아마도 내가 실수를 했나요? 하지만 어디? 나는 워드 프레스 3.9.2

답변

1

'지원'=> 배열 사용 ( '제목', '에디터', '썸네일', '사용자 정의 필드' )

그것은 당신이 보여줄 수 사용자 정의 게시물 유형의 사용자 정의 필드 옵션.

+0

위대한 질문이 있으면 알려 주시기 바랍니다. – Tristup