I'm trying to list all the products tied to a specific taxonomy. For some reason the template won't work when trying to access "http://www.myexample.com/product_categories/funiture/", I tried taxonomy.php
, taxonomy-term.php
and nothing. Here's my code: http://pastie.org/7934453
add_action('init', 'register_cpt_product');
function register_cpt_product() {
$labels = array(
'name' => _x('Products', 'product'),
'singular_name' => _x('Product', 'product'),
'add_new' => _x('Add New Product', 'product'),
'add_new_item' => _x('Add New Product', 'product'),
'edit_item' => _x('Edit Product', 'product'),
'new_item' => _x('New Product', 'product'),
'view_item' => _x('View Product', 'product'),
'search_items' => _x('Search Products', 'product'),
'not_found' => _x('No products found', 'product'),
'not_found_in_trash' => _x('No products found in Trash', 'product'),
'parent_item_colon' => _x('Parent Product:', 'product'),
'menu_name' => _x('Shop', 'shop'),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes'),
'taxonomies' => array('Product Categories'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type('product', $args);
}
add_action('init', 'register_taxonomy_product_categories');
function register_taxonomy_product_categories() {
$labels = array(
'name' => _x('Product Categories', 'product_categories'),
'singular_name' => _x('Product Category', 'product_categories'),
'search_items' => _x('Search Product Categories', 'product_categories'),
'popular_items' => _x('Popular Product Categories', 'product_categories'),
'all_items' => _x('All Product Categories', 'product_categories'),
'parent_item' => _x('Parent Product Category', 'product_categories'),
'parent_item_colon' => _x('Parent Product Category:', 'product_categories'),
'edit_item' => _x('Edit Product Category', 'product_categories'),
'update_item' => _x('Update Product Category', 'product_categories'),
'add_new_item' => _x('Add New Product Category', 'product_categories'),
'new_item_name' => _x('New Product Category', 'product_categories'),
'separate_items_with_commas' => _x('Separate product categories with commas', 'product_categories'),
'add_or_remove_items' => _x('Add or remove product categories', 'product_categories'),
'choose_from_most_used' => _x('Choose from the most used product categories', 'product_categories'),
'menu_name' => _x('Product Categories', 'product_categories'),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'show_admin_column' => false,
'hierarchical' => true,
'rewrite' => true,
'query_var' => true
);
register_taxonomy('product_categories', array('product'), $args);
}
product_categories.php
. If if's not working, go to your taxonomy page in admin, click on "view" for any custom taxonomy, check URL and in the source, the classes on the<body>
tag, it will help you to check what kind of page WP thinks you're on.