how to list all custom post types in current category archive
-
Hi guys and gals, couldn’t find this elsewhere.
I’ve got a site that is using category.php to list custom post types in that category.
For example, my categories structure is like this:
– fruit
— apples
— red
— orange
— yellow
— big
— small
— bananas
— red
— orange
— yellow
— big
— small– veggies
— squash
— red
— orange
— yellow
— big
— small
— carrots
— red
— orange
— yellow
— big
— smallAnd my custom post types are like this:
– red
– green
– big
– smallAll food types share the same set of custom post types (food attributes). What I’m trying to do is direct people toward my second-level category archives (e.g. Carrots) and list the (custom post type) attributes in that category.
Here’s what I’m using now:
<?php $taxonomy = 'category'; $param_type = 'category__in'; $cat_id = get_query_var('cat'); $term_args=array( 'orderby' => 'slug', 'order' => 'ASC', 'child_of' => $cat_id ); $terms = get_terms($taxonomy,$term_args); if ($terms) { foreach( $terms as $term ) { $args=array( "$param_type" => array($term->term_id), 'post_type' => 'big', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $big = null; $big = new WP_Query($args); $get_cat_name = get_cat_name($cat_id); $current_post_date = get_the_date(); if( $get_involved->have_posts() ) { $cat = get_query_var('cat'); while ($big->have_posts()) : $big->the_post(); ?> <?php endwhile; } } wp_reset_query(); ?> <?php } ?>
This has been assembled by a lot of Googling and cut-n-pasting. I’m no PHP guru, but I know a bit.
My problem right now is that I have to categorize each custom post into a ‘red, orange, yellow, big, small’ category to get it to show in the category archive.
What I WANT to do is to get rid of all 3rd level category archives and only categorize the custom post types into the 2nd-level categories (e.g. fruits, veggies).
Any help greatly appreciated!
- The topic ‘how to list all custom post types in current category archive’ is closed to new replies.