我正在尝试将自定义帖子元数据添加到自定义列。元框有两个文本字段,分别是Price和Company,但当我发布一篇新文章时,它只会在Price列和编辑框中显示Company的值,它还会在Price框中检索Company的值!您能告诉我为什么无法在自定义列中检索到正确的值吗?我是否在保存或检索数据时出错?
add_action(\'admin_init\', \'admin_init\');
add_action(\'save_post\', \'save_options\');
function admin_init(){
add_meta_box(
"product_options",
"product",
"normal",
"low"
);
}
function product_opt(){
global $post;
$custom = get_post_custom($post->ID);
$price = $custom[\'price\'][0];
$coMake = $custom[\'coMake\'][0];
echo \'<label style="padding-right:40px;">Price:</label>
<input name="price" value="\'. $price . \'" style="width:250px;" />\';
echo \'<p/ ><label style="padding-right:40px;">Company:</label>
<input name="price" value="\'. $coMake . \'" style="width:250px;" />\';
}
function save_options(){
global $post;
if (!isset($_POST[\'price\']) || $post->post_type != \'product\')
{
return $post;
}
update_post_meta($post->ID, "price", $_POST[\'price\']);
if (!isset($_POST[\'coMake\']) || $post->post_type != \'product\')
{
return $post;
}
update_post_meta($post->ID, "coMake", $_POST[\'coMake\']);
}
add_filter("manage_edit-product_columns", "edit_col" );
add_action("manage_posts_custom_column", "custom_col");
function edit_col($columns){
$columns = array(
"cb" => "<input type =\'checkbox\' />",
"title" => "Product Title",
"price" => "Price",
"coMake" => "Company",
"type" => "Product Type"
);
return $columns;
}
function custom_col($column)
{
global $post;
switch ($column)
{
case "price":
$custom = get_post_custom($post->ID);
echo $custom[\'price\'][0];
break;
case "coMake":
$custom = get_post_custom($post->ID);
echo $custom[\'coMake\'][0];
break;
case "type":
echo get_the_term_list($post->ID, \'type\', \'\', \', \', \'\');
break;
}
}
提前感谢您的评论和帮助