506 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Hey Guys!

I am building a WP site and have categories defined within a post type but can’t work out a way to add a template to display the posts from the categories / taxonomy.

My post type is called product and the taxonomy is category, but the template “taxonomy-category.php” returns nothing in the template.

I have used the basic loop in the template to display the posts.

Any ideas where I am going wrong?

3069 posts
  • Has been a member for 6-7 years
  • Won a Competition
  • Sold between 50 000 and 100 000 dollars
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Exclusive Author
  • Romania
wickedpixel says

that taxonomy is actually named “category” ? That may be a problem because that term is reserved. Also.. that term can be used together with a slug to show certain a certain category in a custom page: http://codex.wordpress.org/Template_Hierarchy#Category_display

506 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Here is my code for the post type, is it possible to display the name of the taxonomy as category but change the name so it doesn’t clash with the restriction?

add_action( 'init', 'product_post_type' );
 function product_post_type() {
  $args = array(
   'labels' => post_type_labels( 'Product' ),
   'public' => true,
   'publicly_queryable' => true,
   'show_ui' => true,
   'show_in_menu' => true,
   'query_var' => true,
   'rewrite' => true,
   'capability_type' => 'post',
   'has_archive' => true,
   'hierarchical' => false,
   'menu_position' => null,
   'taxonomies' => array('category',),
   'supports' => array('title',
    'editor',
    'author',
    'thumbnail',
    'excerpt',
    'comments'
   )
  );
  register_post_type( 'product', $args );
 }
3194 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

prefix that yo!

3069 posts
  • Has been a member for 6-7 years
  • Won a Competition
  • Sold between 50 000 and 100 000 dollars
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Exclusive Author
  • Romania
wickedpixel says
hm, I’m sure that this line:
   'taxonomies' => array('category',),
needs a valid array structure:
   'taxonomies' => array('category'),
506 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

This is confusing, if I change the name to ‘categories’, the categories disappear so it’s being used.

I have tried the following templates to try and make this work:

taxonomy-category-cat-name.php taxonomy-cat.php taxonomy.php category-cat-name.php

Something is definitely fishy here and it’s not being fair…. arghhhhhh

3194 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

the category name is reserved by the core…..

how are you registering your tax?

http://codex.wordpress.org/Function_Reference/register_taxonomy
506 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

My code as follows (changed name to categories)

add_action( 'init', 'product_post_type' );
 function product_post_type() {
  $args = array(
   'labels' => post_type_labels( 'Product' ),
   'public' => true,
   'publicly_queryable' => true,
   'show_ui' => true,
   'show_in_menu' => true,
   'query_var' => true,
   'rewrite' => true,
   'capability_type' => 'post',
   'has_archive' => true,
   'hierarchical' => false,
   'menu_position' => null,
   'taxonomies' => array('categories'),
   'supports' => array('title',
    'editor',
    'author',
    'thumbnail',
    'excerpt',
    'comments'
   )
  );
  register_post_type( 'product', $args );
}

function my_taxonomy() {
       register_taxonomy(
        'categories',
        'product',
        array(
            'hierarchical' => true,
            'label' => 'Categories',
            'query_var' => true,
            'rewrite' => array('slug' => 'category')
        )
    );
    }

    add_action( 'init', 'my_taxonomy' );
60 posts Talk less do more!
  • Elite Author
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 50 000 and 100 000 dollars
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
  • Indonesia
Rifki says

Try with this :


function my_taxonomy() {

        register_taxonomy(__( "product_category" ), 
            array(__( "product" )), 
            array(
                "hierarchical" => true, 
                "label" => __( "Categories" ), 
                "singular_label" => __( "Categories" ), 
                "rewrite" => array(
                    'slug' => 'product-category', 
                    'hierarchical' => true
                )
            )
        ); 

    }

and use taxonomy-product_category.php for the product category display.

506 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Sorted it, created a category.php and using a WP Query to grab the current category.

<?php $my_cat = $wp_query->queried_object->name;

   $args = array(
    'category_name' => $my_cat,
        'post_type' => 'product'
    );
  

Thanks for the help everyone.

by
by
by
by
by
by