• Resolved ohlookitsdany

    (@ohlookitsdany)


    I work at a non-profit and on our older website, I created a custom post type called “Case Studies” a long time ago. I set up a taxonomy within the case studies post type that governs the type of case study (Living Building Challenge, Living Product Challenge, etc). On the existing website, to view the archives for just the specific types, the URL is /programs/$slug.

    We’re currently going through a brand refresh, and I’ve decided to build a new WordPress theme based on Twenty Twenty-Four and I’m trying to change the archive URLs to be /case-studies/$slug, if that makes sense (For example, I want dev.living-future.org/program/lbc to now be dev.living-future.org/case-studies/lbc).

    Additionally, the custom post type has a bunch of custom meta fields that I was originally querying for the old Archive template file on the post cards. Is there a way to query those meta fields when developing a new template in the new WordPress site editor?

    The page I need help with: [log in to see the link]

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

    (@bcworkz)

    Are case-studies a taxonomy or a post type? Which ever way, if the taxonomy/post type is registered with “case-studies” as its key name (or as the rewrite slug name), then the URL should automatically work, though you’ll need to visit the permalinks settings screen (no need to change or save anything) after adding the registration code so the rewrite rules can be regenerated.

    If you want to query for custom meta data as part of a template, use patterns to invoke any PHP code you might need.

    Thread Starter ohlookitsdany

    (@ohlookitsdany)

    Case Studies are a post type (show’s up on the dashboard sidebar as a custom post type) and the type (i.e. which program the entry is a case study for) is a taxonomy. I wrote it a while ago, but I can copy the contents of case-studies.php if that’s helpful.

    Currently, dev.living-future.org/case-studies pulls up the general archive page, but if you want to see the archive of a specific type (LBC Taxonomy for instance), it’s dev.living-future.org/program/lbc. I think I was able to change the rewrite in case-studies.php to make it /case-studies/lbc instead, but when I checked that archive page, it threw a 404 instead.

    Aso for custom meta data, you mention using patterns. I’m pretty new to the new site editor and block themes, so how do you mean?

    Thread Starter ohlookitsdany

    (@ohlookitsdany)

    I realized you shared a link about patterns, my mistake. Please ignore that part of my response.

    Moderator bcworkz

    (@bcworkz)

    /case-studies/lbc/ should take one to a particular single post (“ibc”) of post type “case-studies”. If you recently altered its key name or rewrite slug from something else, did you remember to visit the permalinks settings screen to cause the rewrite rules to regenerate? If you did, and if the post type registration code was set up correctly, and if the “lbc” post really exists, the URL should work. Otherwise something went wrong somewhere among those ifs.

    BTW, it is feasible to introduce custom rewrite rules beyond what WP provides for by default. However you must ensure the matching regex does not conflict with other rewrite rules or you can get strange behavior.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.