Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to have a set of categories for every custom post type.

Book (custom post type) -> category (custom taxonomy) -> Adult / Teenage / Kids

Movie (custom post type) -> category2 (custom taxonomy) -> Thriller / Comedy / Action

So far I manage to display the custom taxonomy as a list:

$terms = get_terms( 'category' );
echo '<ul id ="subnav">';
foreach ( $terms as $term ) {
    $term_link = get_term_link( $term );
    if ( is_wp_error( $term_link ) ) {
    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
echo '</ul>'; 

and in 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');
        $post_type = array('Book');
        return $query;

When I click on Adult/Teenage/Kids it works as I want it, it calls category.php, but when I click on any of Thriller/Comedy/Action it doesn't work.

Any suggestions?

share|improve this question
category is a built in taxonomy, not a custom taxonomy. do you have multiple taxonomies, or are you just using the built in category taxonomy? your second block of code sets post type to book, if you've got another post type you haven't added it to the query. –  Milo Aug 15 '14 at 2:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.