Created
May 27, 2013 01:00
-
-
Save jamiemitchell/5654639 to your computer and use it in GitHub Desktop.
Custom post type with custom taxonomy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Creating the product listing custom post type | |
*/ | |
function product_listing() { | |
$labels = array( | |
'name' => __('Products', 'post type general name'), | |
'singular_name' => __('Product', 'post type singular name'), | |
'add_new' => _x('Add New', 'Product'), | |
'add_new_item' => __('Add New Product'), | |
'edit_item' => __('Edit Product'), | |
'new_item' => __('New Product'), | |
'all_items' => __('All Products'), | |
'view_item' => __('View Product'), | |
'search_items' => __('Search Products'), | |
'not_found' => __('No Products found'), | |
'not_found_in_trash' => __('No Products found in Trash'), | |
'parent_item_colon' => '', | |
'menu_name' => 'Products' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'menu_position' => 4, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'has_archive' => true, | |
'rewrite' => array( 'slug' => 'products', 'with_front' => false ), | |
'supports' => array('title', 'editor', 'thumbnail', 'author'), | |
'taxonomies' => array('product_category'), | |
); | |
register_post_type( 'product' , $args ); | |
} | |
/** | |
* Add custom taxonomies for product listing | |
*/ | |
function product_taxonomies() { | |
$labels = array ( | |
'name' => __( 'Product Categories', 'taxonomy general name' ), | |
'singluar_name' => __( 'Product Category', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Product Category' ), | |
'all_items' => __('All Product Categories'), | |
'parent_item' => __('Parent Product Category'), | |
'parent_item_colon' => __('Parent Product Category:'), | |
'edit_item' => __('Edit Product Category'), | |
'update_item' => __('Update Product Category'), | |
'add_new_item' => __('Add New Product Category'), | |
'new_item_name' => __('New Product Category'), | |
'menu_name' => __( 'Product Categories' ) | |
); | |
register_taxonomy( 'product_category', array('product'), array ( | |
'labels' => $labels, | |
'hierarchical' =>true, | |
'show_ui' => true, | |
'rewrite' => array( 'slug' => 'product_category'), | |
'query_var' => true, | |
'show_in_nav_menus' => true, | |
'public' => true | |
)); | |
} | |
add_action('init', 'product_listing', 0); | |
add_action('init', 'product_taxonomies', 10); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment