[wp-hackers] Custom Post Type Archives

Erick Hitter ehitter at gmail.com
Sun Oct 23 15:26:22 UTC 2011


Daniel,

WordPress doesn't, by default, support pretty permalinks for date-based
post-type archives. You can append query strings to the CPT archive URL and
accomplish what you're looking to do, but if you want nice permalinks, you
need to manually add the rewrite rules.

I added an example at http://pastebin.com/80UEbXs8 that creates the
necessary rules. I pulled this from a project that had many custom post
types, hence the foreach loop. As the function name implies, this code is
tied to the *generate_rewrite_rules* action. Also, to avoid conflicts with
post names, etc., the URLs include a *date* slug between the post type slug
and the date pieces of the URL. This may or may not be needed for your
project, and removing line 14 from the example will eliminate the
*date* element
from the URLs if you don't want/need it.

Erick

On Sat, Oct 22, 2011 at 18:21, Aero Maxx <aero.maxx.d at gmail.com> wrote:

> Hello,
>
> Could someone point me in the right direction in how to make day/month/year
> archives for custom post types.
>
> Normal blog posts get there archives like http://www.domain.co.uk/2010/**
> 12 <http://www.domain.co.uk/2010/12> but can I do something similar for
> custom post types, I was thinking/hoping something like this would work
> http://www.domain.co.uk/lotto/**2010/12<http://www.domain.co.uk/lotto/2010/12>or
> http://www.domain.co.uk/lotto/**2010 <http://www.domain.co.uk/lotto/2010>but these do not work.
>
> I have has_archive set to true, and this does load the
> archive-{post-type}.php file, but I cant get the year/month/day archive to
> work, it just seems to load this page as is, and doesn't seem to know its an
> archive page.
>
> Thank you.
> Daniel.
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>


More information about the wp-hackers mailing list