Create a Custom post with taxonomies

add_action(‘init’,’product_register’);
function product_register()
{
$labels = array(
‘name’ => _x(‘Product’, ‘post type general name’),
‘singular_name’ => _x(‘Product Item’, ‘post type singular name’),
‘add_new’ => _x(‘Add New’, ‘Product item’),
‘add_new_item’ => __(‘Add New Product Item’),
‘edit_item’ => __(‘Edit Product Item’),
‘new_item’ => __(‘New Product Item’),
‘view_item’ => __(‘View Product Item’),
‘search_items’ => __(‘Search Product’),
‘not_found’ =>  __(‘Nothing found’),
‘not_found_in_trash’ => __(‘Nothing found in Trash’),
‘parent_item_colon’ => ”
);

$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => admin_url() . ‘/images/product.png’,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);
register_post_type( ‘product’ , $args );
}
register_taxonomy(“Category”, array(“product”), array(“hierarchical” => true, “label” => “Categories”, “singular_label” => “Category”, “rewrite” => true));

register_taxonomy(‘Size’, array(“product”),   array(‘hierarchical’ => false,   ‘label’ => ‘Size’,’query_var’ =>  true, ‘rewrite’ => true));
// Custom taxonomy for Price
register_taxonomy(‘Price’, array(“product”),   array(‘hierarchical’ => false,   ‘label’ => ‘Price’,’query_var’  => true, ‘rewrite’ => true));
// Custom taxonomy for Brand
register_taxonomy(‘Brand’, array(“product”),   array(‘hierarchical’ => false, ‘label’ => ‘Brand’,’query_var’  => true, ‘rewrite’ => true));
register_taxonomy(‘name’, array(“product”),   array(‘hierarchical’ => false, ‘label’ => ‘Name’,’query_var’  => true, ‘rewrite’ => true));

add_action(“manage_posts_custom_column”,  “product_custom_columns”);
add_filter(“manage_edit-product_columns”, “product_edit_columns”);

function product_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Product Name”,
“description” => “Description”,
“Size” => “<b>Size</b>”,
“Price” => “<b>Price</b>”,
“Brand” => “<b>Brand</b>”,
“name” => “<b>Name</b>”,
“Category” => “<b>Category</b>”,

);

return $columns;
}

function product_custom_columns($column){
global $post;

switch ($column) {
case “description”:
the_content();
break;

case “Price”:
echo get_the_term_list($post->ID, ‘Price’, ”, ‘, ‘,”);
break;
case “Brand”:
echo get_the_term_list($post->ID, ‘Brand’, ”, ‘, ‘,”);
break;
case “name”:
echo get_the_term_list($post->ID, ‘name’, ”, ‘, ‘,”);
break;

case “Category”:
echo get_the_term_list($post->ID, ‘Category’, ”, ‘, ‘,”);
break;

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s