Hi,
I have created a custom post type products and under which I created a custom taxonomy producttype.
Here is the code I used:
function wpstores_custom_taxonomies() {
$labels = array(
'name' => 'Product Types',
'singular_name' => 'Product Type',
'search_items' => 'Search Product Types',
'all_items' => 'All Product Types',
'parent_item' => 'Parent Product Type',
'parent_item_colon' => 'Parent Product Type:',
'edit_item' => 'Edit Product Type',
'update_item' => 'Update Product Type',
'add_new_item' => 'Add New Product Type',
'new_item_name' => 'New Product Type Name',
'menu_name' => 'Product Types',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
);
register_taxonomy( 'producttype', array( 'products' ), $args );
}
add_action( 'init', 'wpstores_custom_taxonomies', 0 );
And, here is the code I am using to create the archive page for the taxonomy terms.
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args = array( 'posts_per_page' => -1, 'post_type' => 'products', 'producttype' => $term->slug,);
$loop = new WP_Query ( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="homesingleproduct">
<figure>
<a href="<?php echo the_permalink(); ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('productpage');} else { echo get_the_title(); }?></a>
<figcaption><?php the_excerpt(); ?></figcaption>
</figure>
<h3 class="producttitle"><a href="<?php echo the_permalink(); ?>"><?php echo get_the_title(); ?></a></h3>
<div class="productdesc"><?php echo get_post_meta($post->ID, 'wssmalldesc', true); ?></div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>'
And, saved that as <code>taxonomy-producttype.php</code>.
It seems not to work at all. Every time I load up the term archive page by
http://www.domain.com/product/plugins/ it loads the index page.
What I am doing wrong?
Thanks