Customising the admin columns for a custom post type, but now most of the built in categories don’t display?

It turns out we had inadvertently created a single conventional category together with our dozen or so custom categories (this probably happened using the WP Ultimate CSV Importer which, for some of our imports, I think we’d filled in the category field hoping it would map to our custom category; it didn’t and we forgot about it).

We checked the wp_term_taxonomy table in the database. It clearly distinguishes the different types of category you’re operating, so this helped us to figure it out.

Having established the cause of the problem, the solution is easy. Just having 'categories' => 'Categories', and hoping it will pick up your custom categories is never going to work.

We needed to explicitly pull in the categories, just like any other custom field on a custom post type. Like so, using get_the_term_list:

add_action('manage_posts_custom_column', 'manage_myproduct_custom_column',10,2);
function manage_myproduct_custom_column($column_key,$post_id) {
    global $pagenow;
    global $wpdb;
    $post = get_post($post_id);

    if ($post->post_type=='myproduct' && is_admin() && $pagenow=='edit.php')  {
        //echo ( get_post_meta($post_id,$column_key,true) ) ? get_post_meta($post_id,$column_key,true) : "";        
        switch ( $column_key) {
            case "myproduct_categories":
                  echo get_the_term_list($post->ID,'myproduct_categories','',', ','');
                  break;        
            case "myproduct_foobar":
                  if(get_post_meta( $post_id, 'myproduct_foobar', true)=='Available') {echo 'Y';};
                  break;

        }
    }
}