Skip to content

@scribu /gist:856587
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
'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
Something went wrong with that request. Please try again.