Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

closed as too localized by toscho May 17 '13 at 18:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Your input fields has the same name:

<input name="price" ...
share|improve this answer
    
OMG! what a Silly Mistake! Thanks richard –  Behseini May 17 '13 at 18:51
add comment

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