Support » Plugins » Hacks » Custom Post Type Category Archives

  • I’ve been searching high and low for two days and none of the posts online have gotten me anywhere. The website in question has categories and four post types. The post types all share the categories. I have my CPT archives working just fine. works like a charm.

    What I now need is


    This is what I’m currently trying without any success whatsoever no matter how I tweak it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    Hi Rebecca, a wild guess, could your category request be getting matched to the generic CPT rewrite and handled before the category rewrite even gets a chance?

    If that’s not it, you could try hooking the filter ‘posts_request_ids’ just to see how the query ended up. A good clue as to where things went wrong.

    If all else fails, you could massage the query via one of the other ‘posts_*’ filters, but the parser would at least need to recognize it’s a category request to set the is_category() tag. If things get really desperate, you could create your own handler.

    Good luck tracking this down,

    Thanks for the input, bc. I think you’re right. I’d tried adding higher priority to my rule, and it broke all the archives.

    I finally got it to work by appending the CPT to the end of the category rewrite.


    The only drawback here is now, within the categories, the post type must be identified by name rather than slug. Some of them have custom slugs – ice_cream may have the slug delicious_frozen_goodness, for example. (Personally not too happy about this, it was a cosmetic change requested halfway into the project.) The archive for the CPT will be accessed directly

    But the archive for the category/CPT combo needs to be accessed as

    Any thoughts on the rewrite there? I’m guessing it’s something extremely obvious that I’m missing.

    I’m also experiencing a few ancillary issues now, including the global conditional statements not always working. For example, is_front_page(), is_home(), is_single(), etc aren’t operating as expected. I’m going to venture a guess that this is because of previous code I still have active that muddied up the system, so a code clean-up is in order.

    Thanks again!

    Moderator bcworkz


    Sorry, no easy answers from me, I often can’t see where the problem is without seeing the result. Either the parser is not parsing the way you expect, or the query is not getting the query vars it expects, so is building the wrong query. The later would explain why the is_*() tags aren’t working.

    You can look at the query vars by hooking the ‘request’ filter and doing a var_dump(); die();. That’ll give you a clue where the problem lies, as this is after the parser but before the query is built.

    It was a collision with a function. I’d kind of screwed around with making it work before realizing I’d missed an obvious solution, so my code was…messy.

    New problem: RSS links don’t work with that rewrite rule.

    I’ve edited it to this


    In the hopes it would work, but, alas. Nothing. I’m going to try using rewrite endpoints and just appending the CPTs to that.

    Ideally, the permalink structure would look like this (here is where everything stops working)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type Category Archives’ is closed to new replies.