2012-10-09 45 views
3

對於我爲客戶建立的Wordpress網站上的Post Array問題,我感到非常困惑。我希望以前有人看到過這個!管理面板中的Wordpress Post Array的奇怪問題

我已經註冊了一個自定義文章類型:

register_post_type('products', array(
    'labels' => array(
     'name' => __('Products'), 
     'singular_name' => __('Product'), 
    ), 
    'public' => true, 
    'menu_position' => 20, 
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments',), 
    'taxonomies' => array('category'), 
    'capability_type' => 'post', 
    'rewrite' => array('slug' => 'products','with_front' => TRUE), 
    'register_meta_box_cb' => 'product_page_meta_box' 
)); 

在我所註冊的回調以下meta框:

function product_page_meta_box() { 
    add_meta_box('product_meta_box_content', 'Product Specifications', 'product_meta_box_content', 'products'); 
} 

function product_meta_box_content($post) { 

    wp_nonce_field(plugin_basename(__FILE__), 'product_noonce'); 

    echo '<div class="inside>'; 
     var_dump($post); 
     echo '<p>Please detail the product specifics here:</p>'; 
    echo '</div>'; 
} 

挫折我就是的var_dump結果以上在管理頁面上是:

string(3) "258" ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2012-08-27 19:33:30" ["post_date_gmt"]=> string(19) "2012-08-27 19:33:30" ["post_content"]=> string(0) "" ["post_title"]=> string(10) "The Wensum" ["post_excerpt"]=> string(20) "Testing the excerpt!" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(22) "large-6-perch-dovecote" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2012-10-04 16:50:19" ["post_modified_gmt"]=> string(19) "2012-10-04 16:50:19" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> string(1) "0" ["guid"]=> string(53) "http://dovecotes.local//?post_type=products&p=258" ["menu_order"]=> string(1) "0" ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["ancestors"]=> array(0) { } ["filter"]=> string(4) "edit" } 

在管理區域它沒有類型,並且是co完全無效;有關雖然接線柱陣列是好的頁面上,該ID有一個關鍵,這是一個有效的對象:

object(stdClass)#145 (25) { ["ID"]=> int(258) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2012-08-27 19:33:30" ["post_date_gmt"]=> string(19) "2012-08-27 19:33:30" ["post_content"]=> string(0) "" ["post_title"]=> string(10) "The Wensum" ["post_excerpt"]=> string(20) "Testing the excerpt!" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(22) "large-6-perch-dovecote" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2012-10-04 16:50:19" ["post_modified_gmt"]=> string(19) "2012-10-04 16:50:19" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(54) "http://dovecotes.local//?post_type=products&p=258" ["menu_order"]=> int(0) ["post_type"]=> string(8) "products" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["ancestors"]=> array(0) { } ["filter"]=> string(3) "raw" } 

回答

0

我不能保證這會工作,但使用「register_meta_box_cb我一直迴避'在定義自定義帖子類型時贊成'add_meta_boxes'動作鉤子。

除了'supports'參數中的逗號之外,你的代碼看起來是正確的,所以在你的例子中沒有任何東西會讓我相信它的任何一個都可能是罪魁禍首,除非它是一個優先級差異。我也不能肯定如果ID和回調參數允許在你的metabox參數是相同的,所以我花了改變,太多的自由:

register_post_type('products', array(
    'labels' => array(
     'name' => __('Products'), 
     'singular_name' => __('Product'), 
    ), 
    'public' => true, 
    'menu_position' => 20, 
    'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments'), 
    'taxonomies' => array('category'), 
    'capability_type' => 'post', 
    'rewrite' => array('slug' => 'products','with_front' => TRUE) 
)); 
add_action('add_meta_boxes', 'product_page_meta_box'); 
function product_page_meta_box() { 
    add_meta_box('product_meta_box_content', 'Product Specifications', 'product_meta_box_content_cb', 'products'); 
} 

function product_meta_box_content_cb($post) { 

    wp_nonce_field(plugin_basename(__FILE__), 'product_noonce'); 

    echo '<div class="inside>'; 
     var_dump($post); 
     echo '<p>Please detail the product specifics here:</p>'; 
    echo '</div>'; 
} 

如果沒有幫助,那麼我不知道沒有看到更多的代碼會是什麼。

+0

嗨,謝謝你的回覆@ maiorano84。 我已經嘗試過這兩種方式,不幸的是結果是一樣的,你認爲哪些代碼會有所幫助? – Illizian

+0

對不起,錯過了有關回撥的部分,ID會稍後改變這些內容,並讓您知道它是否有幫助! – Illizian