Skip to content

Instantly share code, notes, and snippets.

@scribu
Created March 5, 2011 18:34
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/856587 to your computer and use it in GitHub Desktop.
Save scribu/856587 to your computer and use it in GitHub Desktop.
'product' post type + 'color' taxonomy
<?php
// Register the post type and taxonomy
function init_product_cpt() {
register_post_type( 'product', array(
'public' => true,
'label' => __( 'Products', 'my-plugin' )
) );
register_taxonomy( 'color', 'product', array(
'label' => __( 'Color', 'my-plugin' )
) );
}
add_action( 'init', 'init_product_cpt' );
// Register the column
function color_column_register( $columns ) {
$columns['color'] = __( 'Color', 'my-plugin' );
return $columns;
}
add_filter( 'manage_edit-product_columns', 'color_column_register' );
// Register the column as sortable
function color_column_register_sortable( $columns ) {
$columns['color'] = 'color';
return $columns;
}
add_filter( 'manage_edit-product_sortable_columns', 'color_column_register_sortable' );
// Display the column content
function color_column_display( $column_name, $post_id ) {
if ( 'color' != $column_name )
return;
the_terms( $post_id, 'color' );
}
add_action( 'manage_posts_custom_column', 'color_column_display', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment