• Hello,

    How can I view my custom post types in the normal categoryies? I added the category to the custom post type as taxonomy. When I read the (custom post type) post it highlights the specific category. But when I click on the specific category in the list, the (custom post type) post doesn’t show up!!

    How is that possible. Don’t they interact?

    Regards,
    Martin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Put this in your theme’s functions.php:

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
    if($query->is_archive){
      if(is_category() || is_tag()) {
        if (empty( $query->query_vars['suppress_filters'])) {
          $post_type = get_query_var('post_type');
    
    	    if($post_type) {
    	      return $query;
    	    } else {
    	      $post_type = array('post','my_post_type');
            $query->set('post_type',$post_type);
    	      return $query;
          }
        }
      }
     }
    return $query;
    }

    And put your post type in the $post_type array:
    post_type = array('post','my_post_type');

    Thread Starter MartinLeclercq

    (@martinleclercq)

    tnx for your input! That works like a charm.

    I’m also using a plugin ‘Folding Category list’ (FoCaL). You can choose NOT to show the empty categories in the list. All the categories with custom post types then also disappear.

    Probably a bug in the plugin. Damn. Probably have to make a accordion list myself then. Or does anybody know a sollution?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom post type and Category’ is closed to new replies.