1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
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?

3072 posts
  • Affiliate Level 3
  • Author Level 6
  • Collector Level 2
  • Weekly Top Seller
+7 more
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

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
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 );
 }
3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 more
organicbee
says

prefix that yo!

3072 posts
  • Affiliate Level 3
  • Author Level 6
  • Collector Level 2
  • Weekly Top Seller
+7 more
wickedpixel
says
hm, I’m sure that this line:
   'taxonomies' => array('category',),
needs a valid array structure:
   'taxonomies' => array('category'),
1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
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

3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 more
organicbee
says

the category name is reserved by the core…..

how are you registering your tax?

http://codex.wordpress.org/Function_Reference/register_taxonomy
1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
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' );
70 posts Talk less do more!
  • Weekly Top Seller
  • Affiliate Level 2
  • Author Level 7
  • Collector Level 3
+3 more
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.

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
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