0

I am trying to add Custom post Metadata to a Custom Column. The meta-box has two text fields as Price and Company but When I publish a new post it just shows values from company in Price column and edit box also it retrieves the company value inside the Price box! Can you please let me know why I cant' retrieve the correct value in Custom Column? Am I doing something wrong in saving or retrieving the data?

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;
}
   }

Thanks for comments and helps in advance

1

Your input fields has the same name:

<input name="price" ...
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.