Categories for custom post types – am I doing this right, is there a better way?
-
I have a site comprised of pages, posts and three custom post types, respectively; guides, videos, images.
I’m having to use custom post types to this end as the site needs to have archive views for each of the above formats. Images must be a post type as opposed to standard media library attachments as there is need to restrict which images comprise a gallery, and requirements to categorise and tag these, individually.
I have categories and tags all over which are shared between post types for example, the category term ‘summer’ could apply to a post, a guide post type, or an image post type.
Further, there is requirements to visually break down the posts so, front-page.php loops through all post types, outputting them accordingly. A sub-nav allows you to navigate to each of the post types individually, ‘Articles’ links to a page template outputting only posts, videos, guides, images run through archive.php
In the header of each of these pages is a category selector, which should list each of the terms the current post type is assigned to for example, if a guide post has a term of ‘tip sheet’, this will be listed. Conversely, if a video does not have a post assigned to the term ‘tip sheet’, this will not be listed.
Selecting a term from the select box, navigates to the category page which is where things get messy.
The only way i’ve been able to restrict to the relevant post type is by using the slug structure domain.com/category/term/?post_type=guides
This works however I suspect this is very wrong. It’s also requiring some messy conditional logic to ensure that each of the post types is restricted, and that that the view all option (front-page.php) lists all post types accordingly.
Is there a better way?
Ideally, i’m thinking it should be something like domain.com/post-type/category/term ?
I’m aware you can declare a ‘category’ taxonomy for each of the custom post types however would this make them capable of being shared between post types?
- The topic ‘Categories for custom post types – am I doing this right, is there a better way?’ is closed to new replies.