A problem with date archives

The problem is that the plugin only handles the calendar part, and not the archive query.

What you need to do:

Change the main query on archive pages if the post_type argument is present, eg: http://localhost:8888/wp/?m=201105&post_type=candy :

add_filter('pre_get_posts', 'atom_include_cpt_in_archives');

function atom_include_cpt_in_archives($query){
  // validate
  if(is_archive() && isset($_GET['post_type']) && post_type_exists($_GET['post_type']))
    $query->set('post_type', $_GET['post_type']);

  return $query;
}

Next, you’ll have to make your own get_calendar() version, because the native function is not hookable:

  • add a $post_type argument to the function and change all the db queries:

    WHERE post_type="post" to WHERE post_type = $post_type

  • append the current post type that’s being requested to get_month_link() / get_day_link():

    add_query_arg('post_type', $post_type, get_month_link($previous->year, $previous->month))

  • maybe override the $post_type function argument with the query argument if it’s set:

    if(isset($_GET['post_type']) && post_type_exists($_GET['post_type'])) $post_type = $_GET['post_type'];

I did a calendar widget like this which among other things, supports CPT. I could post the code, but since it’s part of a theme framework you’d have to figure it out yourself how to separate it 🙂