0

I'm confused.

  • I have a custom post type "asset".
  • I created posts, and they are all at /asset/post-title
  • I assigned categories to the custom post type, e.g. "patterns"
  • The categories page shows the number of posts in each category
  • If you look at the post meta for any of these posts in single view, it displays the category(ies) assigned to it.

HOWEVER, it you click the category link in the post meta ("patterns"), I get a page "nothing found".

If I assign the category to a normal post type, those will show of the category page.

What did I forget?

EDIT: I should also add that the LINK for "patterns" is /category/patterns

0

By default, category archives only show posts of the default 'post' type. The below code should get it working how you want. —via CSS Tricks

function namespace_add_custom_types( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
            'post', 'your-custom-post-type-here'
        ));
        return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
  • You have a couple of problems here. You should always make sure that you understand the code you are copying and adding as an answer. I had to clean up the mess. Check it out here – Pieter Goosen Jul 25 '14 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.