I would like to implement date-based archive functionality (similar to original WP Archives widget functionality) for custom post type (CPT). What makes it difficult is the fact that I need to group and archive events not by published date, but by event_date stored as a meta value.

For example, I have event CPT registered as following:

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'has_archive' => 'past-events',
    'rewrite' => array('slug' => 'event','with_front' => false),
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'show_in_nav_menus' => false,
    'menu_position' => 15,
    'supports' => array(

I would like to generate archive links like /past-events/2011/04, similar to the functionality of WP Archives widget. However, my events should be archived by the event_date meta value. Also, if, say for April 2011, there are more events than my Blog pages show at most setting, I would like to have a correct pagination for pages. And ideally, when viewing a single event I would have correct previous and next event links within that archive page. Hope that makes sense.

I'm using WP3.1 I've gone as far as specifing has_archive setting for the CPT. I did look around, but got confused how to proceed. Is that something I have to write myself or it could be done with WP functions or plugins?

Would really appreciate any help and tips.

Many thanks, Dasha

  • You can't achieve that with the build in functions nor do i know of any plugin that would help you do that and to write this kind of functionality would mean a lot of code.... but there might be a simpler solution, So in what format is your event_date meta value?
    – Bainternet
    Commented Apr 14, 2011 at 19:30
  • @Bainternet, it's stored as a string "YYYY-MM-DD".
    – dashaluna
    Commented Apr 14, 2011 at 20:12
  • Ok so a suggested solution would be to modify the post_date field based on your 'event_date' meta value on save_post action hook, that way you could use all build in function in a regular manner.
    – Bainternet
    Commented Apr 15, 2011 at 2:21
  • @Bainternet will this affect when events appear on the site? What I means is when I create a future event, say 2 month ahead, I want it to show up on the site. I think if I change the post_date the event will be published on that date and won't be seen before that?
    – dashaluna
    Commented Apr 15, 2011 at 9:03
  • Not sure if that will happen, i just tried changing a post_date to 22-03-2012 and it showed up just fine.
    – Bainternet
    Commented Apr 15, 2011 at 14:17

1 Answer 1


This doesn't answer your question fully but it's an attempt to help.

Take a look at: http://seebz.net/notes/#note-145 Sets up a CPT with date archives and sets up all the necessary rewrite rules.

As for using wp_get_archives() it doesn't have the necessary hooks of filters for it to work with a CPT so I recommend that you copy the function and alter to your liking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.