0

I know there's a name for every kind of template. archive-CPT.php, or single-CPT even taxonomies taxonomy-taxonomyname.php but, what's the name I should use for the template that have my yearly archive?

1 Answer 1

2

CPT's don't have date archives, those are a post specific feature.

Having said that, nothing prevents you building a custom bespoke date archive for a CPT. Just don't expect WordPress core to do it for you, it would be a 100% custom job, you'd have to load your own date templates, modify the query, add the rewrite rules, and construct the URLs yourself.

The closest you can get out of the box, is visiting a CPT's archive, and appending query args to the URL, e.g. example.com/yourcpt?year=2022, but this will give you the same archive as that URL but with the additional filtering to 2022. Note that this only works with standard archives, it will not work if you replace the main query, rely on page templates to recreate archives, or use a page builder. It also won't be considered a date archive by WordPress functions and APIs

4
  • Isn't the wp_get_archives(); bring me to a link of every post yearly, monthly and even daily? The url's already exist... que query is almost the same, but rewrite the rules are the things that gives me nightmares. Oct 6, 2021 at 1:49
  • Do you have an existing/custom archive.php or index.php file? If not, and you can’t foresee using one just take a copy from the parent theme, add to your child theme and modify as needed. Ideally taking archive.php as it’s closer to what you want. Also you can look at the wp file structure and see which one is most appropriate.
    – tiadotdev
    Oct 6, 2021 at 4:32
  • Only post's come with a date archive out the box, the permalinks/templates/etc don't exist for other post types. Nothing prevents date archives for CPTs it just is not implemented in WordPress.
    – Tom J Nowell
    Oct 6, 2021 at 8:49
  • @tiaMCQD there is no archive, WP doesn't support date archives out the box for other post types so there is no file to load. It doesn't matter if the OP already has a written up template for their CPT's date archive because there are no CPT date archives
    – Tom J Nowell
    Oct 6, 2021 at 8:50

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.