Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: JTWilcox on Jun 20th, 2011  |  syntax: PHP  |  size: 1.35 KB  |  hits: 321  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Custom columns in Admin view
  2. add_action("manage_posts_custom_column", "my_custom_columns");
  3. add_filter("manage_edit-professionals_columns", "my_professionals_columns");
  4.  
  5. function my_professionals_columns($columns)
  6. {
  7.         $columns = array(
  8.                 "cb" => "<input type=\"checkbox\" />",
  9.                 "title" => "Name",
  10.                 "titles" => "Group",
  11.                 "phone-o" => "Phone - Office",
  12.                 "phone-c" => "Phone - Cell",
  13.                 "email" => "Email",
  14.                 "lastname" => "Last Name"
  15.         );
  16.         return $columns;
  17. }
  18.  
  19. function my_custom_columns($column){
  20.         global $post;
  21.         switch($column){
  22.                 case "phone-o":
  23.                     $custom = get_post_custom();
  24.                     echo $custom["prof_phone-o"][0];
  25.                     break;
  26.                 case "phone-c":
  27.                     $custom = get_post_custom();
  28.                     echo $custom["prof_phone-c"][0];
  29.                     break;
  30.                 case "email":
  31.                     $custom = get_post_custom();
  32.                     echo $custom["prof_email"][0];
  33.                     break;
  34.                 case "lastname":
  35.                     $custom = get_post_custom();
  36.                     echo $custom["prof_lastname"][0];
  37.                     break;
  38.                 case "titles":
  39.                     // Get terms for post
  40.                         $terms = get_the_terms( $post->ID , 'titles' );
  41.                        
  42.                         // Loop over each item since it's an array
  43.                         foreach( $terms as $term ) {
  44.                                 // Print the name method from $term which is an OBJECT
  45.                                 print $term->name . '<br />';
  46.                                 // Get rid of the other data stored in the object, since it's not needed
  47.                                 unset($term);
  48.                         }
  49.                     break;
  50.         }
  51. }