Support » Themes and Templates » Archive Page for Custom Taxonomy in Custom Post Type

  • Abhik


    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">
    			<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>
    			<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>
    	<?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 it loads the index page.

    What I am doing wrong?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Abhik


    Nevermind, I get it working.



    Hi Abhik,

    Would you mind letting me know how you got it working? I am having issues with taxonomy archives ever since I updated a site to 3.5.1


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Archive Page for Custom Taxonomy in Custom Post Type’ is closed to new replies.