1

(Since my custom post type is a little long, I've for the sake of simplicity, copied over a dummy one)

What I am trying to do is, say I describe a few "similar" variables, i.e. price1, price2, price3, etc. would I be able to stack those values in a single column (as opposed to showing it over 3 columns), i.e. $price1<br />$price2<br />$price3 ? The reasons are purely aesthetic as the custom post type columns would get really crowded quickly otherwise.

Thank you! (like said, the part below isn't the actual code I'm using, but I thought it would be good if someone else would be searching the same thing)

add_filter("manage_edit-product_columns", "prod_edit_columns");
add_action("manage_posts_custom_column",  "prod_custom_columns");

function prod_edit_columns($columns){
  $columns = array(
   "cb" => "<input type=\"checkbox\" />",
   "title" => "Product Title",
   "description" => "Description",
   "price1" => "Price1",
   "catalog" => "Catalog",
  );

  return $columns;
}

function prod_custom_columns($column){
  global $post;
  switch ($column)
  {
   case "description":
    the_excerpt();
    break;
   case "price": // Now here I have to define the field, but how would I drag in other subsequent price fields?
    $custom = get_post_custom();
    echo $custom["price"][0];
    break;
   case "catalog":
    echo get_the_term_list($post->ID, 'catalog', '', ', ','');
    break;
  }
}

1 Answer 1

3

yea you can do just that. you only need to change the output function which in this case is

function prod_custom_columns($column){
  global $post;
  switch ($column)
  {
   case "description":
    the_excerpt();
    break;
   case "price": // Now here I have to define the field, but how would I drag in other subsequent price fields?
    $custom = get_post_custom();
    echo $custom["price"][0];
    break;
   case "catalog":
    echo get_the_term_list($post->ID, 'catalog', '', ', ','');
    break;
  }
}

to display what you want for each column say your price change it to something like:

case "price": // Now here I have to define the field, but how would I drag in other subsequent price fields?
    $custom = get_post_custom();
    echo $custom["price"][0];
    echo 'br />';
    echo $custom["another_FIELD"][0];
    echo 'br />';
    echo $custom["yet_another_FIELD"][0];
    break;

hope this helps

1
  • Duh, it's actually exactly the code I had in there, but didn't expect it to function for some reason. Thanks!
    – Noel Tock
    Commented Jan 31, 2011 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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