0
votes

I've spent a few hours googling this but had no joy....

url: http://workflow.wearepixel.co.uk/product/tall-cabinets/

I have the custom post type 'product' and a cpt post with the category 'tall-cabinets'. I just need the custom post categories to display on a shared template (such as taxonomy.php)

I've tried all the standard templates, category.php, taxonomy.php, archive.php, category-product.php, taxonomy-product.php, archive-product.php... and god knows how many scripts...

Unfortunately taxonomy-product-tall-cabinets.php won't work either and won't do as I need to have a default template for all cpt categories.

Please can anyone help?

fixed. Add this to functions.php:

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if(is_category() || is_tag()) {
    $post_type = get_query_var('post_type');
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('post','<strong>cpt</strong><strong>'); // replace cpt to your custom post type
    $query->set('post_type',$post_type);
    return $query;
    }
}
1
can u examine all products ? <pre><?=print_r($products,true);?></pre> later using a foreach sentence you can find if a given product belongs to a category.christian
I can on the custom post type archive, but not the category of that: workflow.wearepixel.co.uk/productleannekera

1 Answers

0
votes

I had a similar issue, the only thing i can see different to the code i use and the code you have put here is you are looking for tags as well.

 if(is_category() || is_tag()) {

i dont use the tag part, but my tags are still displayed.

Also this line

        $post_type = array('post','<strong>cpt</strong><strong>'); // replace cpt to your custom post type

try adding 'nav_menu_item' to your array

$post_type = array('nav_menu_item', 'post','<strong>cpt</strong><strong>');

that should add the menu items

my full code:

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
    $post_type = get_query_var('post_type');
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('nav_menu_item', 'post', 'case_study'); 
    $query->set('post_type',$post_type);
    return $query;
    }
}