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(
'title',
'editor',
'author',
'revisions'
)
);
register_post_type('event',$args);
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
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.