898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 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
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 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

898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 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 );
 }
3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

prefix that yo!

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel says
hm, I’m sure that this line:
   'taxonomies' => array('category',),
needs a valid array structure:
   'taxonomies' => array('category'),
898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 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

3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 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
898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 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!
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+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.

898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by