Forums

How to archive monthly or yearly custom post types? (7 posts)

  1. markzero
    Member
    Posted 1 year ago #

    Hello,

    I am using WP 3.1 and having issues with archives.

    I know wp_get_archives does the trick, but how to do it for post types other than 'post' types (usual ones) ?

    Also, how to get the template working for e.g. http://www.example.com/movies/2011/02 ? (if custom post types are 'movies')

  2. fonglh
    Member
    Posted 1 year ago #

    I had to do this for a website I'm working on and wrote about it in a blog post.

    Basically you have to add 'has-archives=>true' to register_post_type() and add a filter to getarchives_where.

    If you want a custom template, name it archive-movies.php

  3. markzero
    Member
    Posted 1 year ago #

    Thanks for the info, it helped getting the archives list, by month!

    But template is just not working.. I have the file but it redirects to home page..

    Any clue?

  4. fonglh
    Member
    Posted 1 year ago #

    oh oops the right key is 'has_archive'.

    Strangely it has stopped working for me although it worked yesterday and nothing has changed. I'm trying to figure out which template file it gets directed to.

    The template thing works for me, but fails as soon as I add the year and month. So example.com/movies goes to archive-movies.php, but I have no idea where example.com/movies/2011/02 is ending up. It doesn't find anything even though the posts are there.

  5. web00132
    Member
    Posted 7 months ago #

    I'm having the exact same problem, @fonglh - please say you did solve this? I'm not even getting the cpt home page, I get straight to the 404 page.

  6. fonglh
    Member
    Posted 7 months ago #

    Check out the series of blog posts I linked to in the first reply. I'm not really sure why it works, so I just summarized what I did and didn't touch it anymore.

  7. web00132
    Member
    Posted 7 months ago #

    Ok cool, thanks for your reply. I'll check it out asap.

Topic Closed

This topic has been closed to new replies.

About this Topic