Wordpress自定义帖子类型问题

时间:2011-08-05 10:51:13

标签: wordpress templates custom-post-type

尝试添加自定义帖子类型哪个成功我遇到的问题是添加元数据和这些帖子类型的输入在这里是我的代码: 的functions.php     add_action(“admin_init”,“admin_init”);

    function admin_init(){
        add_meta_box("deal-meta", "Deal Options", "deal_options", "deal", "side", "low");
    }

    function deal_options(){
        global $post;
        $custom = get_post_custom($post->ID);
        $price = $custom["price"][0];
        $discount = $custom["discount"][0];
        $market_value = $custom["market_value"][0];
        $start_date = $custom["start_date"][0];
        $end_date = $custom["end_date"][0];
        $highlights = $custom["highlights"][0];
        $fine_print = $custom["fine_print"][0];
        $quick_description = $custom["quick_description"][0];
        ?>
        <label>Price:</label>
        <input name="price" value="<?php echo $price; ?>" />

        <label>Discount:</label>
        <input name="discount" value="<?php echo $discount; ?>" />

        <label>Market Value:</label>
        <input name="market_value" value="<?php echo $market_value; ?>" />

        <label>Start Date:</label>
        <input name="start_date" value="<?php echo $start_date; ?>" />

        <label>End Date:</label>
        <input name="end_date" value="<?php echo $end_date; ?>" />

        <label>Highlights:</label>
        <textarea cols="50" rows="5" name="highlights"><?php echo $highlights; ?></textarea>

        <label>Fine Print:</label>
        <textarea cols="50" rows="5" name="fine_print"><?php echo $fine_print; ?></textarea>

        <label>Quick Description:</label>
        <textarea cols="50" rows="5" name="quick_description"><?php echo $quick_description; ?></textarea>
        <?php
    }

    add_action('save_post', 'save_details');

    function save_details(){
        global $post;

        update_post_meta($post->ID, "price", $_POST["price"]);
        update_post_meta($post->ID, "discount", $_POST["discount"]);
        update_post_meta($post->ID, "market_value", $_POST["market_value"]);
        update_post_meta($post->ID, "start_date", $_POST["start_date"]);
        update_post_meta($post->ID, "end_date", $_POST["end_date"]);
        update_post_meta($post->ID, "highlights", $_POST["highlights"]);
        update_post_meta($post->ID, "fine_print", $_POST["fine_print"]);
        update_post_meta($post->ID, "quick_description", $_POST["quick_description"]);
    }

然而,当我去添加交易时,它没有显示任何这些,很困惑。

任何帮助将不胜感激

由于 戴夫

Var转储:

array(2) {
  ["deal"]=>
  array(2) {
    ["side"]=>
    array(2) {
      ["core"]=>
      array(2) {
        ["submitdiv"]=>
        array(4) {
          ["id"]=>
          string(9) "submitdiv"
          ["title"]=>
          string(7) "Publish"
          ["callback"]=>
          string(20) "post_submit_meta_box"
          ["args"]=>
          NULL
        }
        ["Citiesdiv"]=>
        array(4) {
          ["id"]=>
          string(9) "Citiesdiv"
          ["title"]=>
          string(6) "Cities"
          ["callback"]=>
          string(24) "post_categories_meta_box"
          ["args"]=>
          array(1) {
            ["taxonomy"]=>
            string(6) "Cities"
          }
        }
      }
      ["low"]=>
      array(1) {
        ["postimagediv"]=>
        array(4) {
          ["id"]=>
          string(12) "postimagediv"
          ["title"]=>
          string(14) "Featured Image"
          ["callback"]=>
          string(23) "post_thumbnail_meta_box"
          ["args"]=>
          NULL
        }
      }
    }
    ["normal"]=>
    array(1) {
      ["core"]=>
      array(1) {
        ["slugdiv"]=>
        array(4) {
          ["id"]=>
          string(7) "slugdiv"
          ["title"]=>
          string(4) "Slug"
          ["callback"]=>
          string(18) "post_slug_meta_box"
          ["args"]=>
          NULL
        }
      }
    }
  }
  ["post"]=>
  array(1) {
    ["side"]=>
    array(1) {
      ["low"]=>
      array(1) {
        ["deal-meta"]=>
        array(4) {
          ["id"]=>
          string(9) "deal-meta"
          ["title"]=>
          string(12) "Deal Options"
          ["callback"]=>
          string(12) "deal_options"
          ["args"]=>
          NULL
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

试试这个......

add_action("add_meta_boxes", "my_add_meta_boxes");
function my_add_meta_boxes(){
    add_meta_box("deal-meta", "Deal Options", "deal_options", "deal", "side", "low");
}

如果有效,请告诉我。

---- ---- EDIT

尝试在plugins目录中添加以下插件作为插件。禁用您的插件,启用测试插件,并添加帖子。元数据框应位于帖子编辑屏幕的底部。

<?php
/*
Plugin Name: Metabox Test
*/

add_action("plugins_loaded", "metaboxtest_action_plugins_loaded");

function metaboxtest_action_plugins_loaded(){
    add_action("add_meta_boxes", "metaboxtest_action_add_meta_boxes");
}

function metaboxtest_action_add_meta_boxes(){
    add_meta_box("metabox-test", 
        "Testing", 
        "metaboxtest_metabox_output", 
        "post");
}

function metaboxtest_metabox_output(){
    echo "Hello World";
}
相关问题