WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know this is a rather common topic, but I can't seem to resolve the issue I'm having. Any help is greatly appreciated, I'm spinning my wheels at this point.

Using Custom Post Type UI plugin, I've created some custom post types (I'll use 'blog' in this example). I've set has_archive => true, and I've also used a plugin called Custom Post Type Archives to get my pagination to work properly. So far, I have my permalinks, tags, categories and pagination working. However, the issue is when I try to use the wp_get_archives function. I understand this doesn't grab CPTs, so I've used the function that comes with the Custom Post Type Archives Plugin (wp_get_custom_post_archives). Depending on how I tweak the arguments, it spits out either a 404, or it loads the archives, but just displays every entry (not just those specific to the selected month). Ideally, I just want it to display monthly archives.

<?php wp_get_post_type_archives('blog');

Take a look here: http://www.metropoliscreative.com/coding/w/blog/

I've used this to register the post type and believe I've done it properly. Not sure what I'm doing wrong at this point.

register_post_type('blog', array(   
        'label' => 'Blog',
        'description' => 'Blog Entries',
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array(
            'slug' => 'blog'),
        'has_archive' => true,
    'query_var' => true,
    'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),
    'taxonomies' => array('category','post_tag',),
    'labels' => array (
      'name' => 'Blog',
      'singular_name' => 'Blog',
      'menu_name' => 'Blog',
      'add_new' => 'Add Blog',
      'add_new_item' => 'Add New Blog',
      'edit' => 'Edit',
      'edit_item' => 'Edit Blog',
      'new_item' => 'New Blog',
      'view' => 'View Blog',
      'view_item' => 'View Blog',
      'search_items' => 'Search Blog',
      'not_found' => 'No Blog Found',
      'not_found_in_trash' => 'No Blog Found in Trash',
      'parent' => 'Parent Blog',
    ),) );
share|improve this question
Since has_archive was new in 3.1 (I think) it is very likely that one of those plugins might be not using it. – Wyck Apr 5 '11 at 18:12
Wyck, I think you're right. It's not negatively affecting what I'm doing, though (I don't think). If I remove it, I can't get to blog/page/2 without a 404. – Redlist Apr 5 '11 at 18:29

You can use getarchives_where hook of wp_get_archives() function

Add this function to your functions.php:

function Cpt_getarchives_where_filter( $where , $r ) {

  $post_type = 'blog';
  return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where );

Then when you want your monthly archive put this:

add_filter( 'getarchives_where' , 'Cpt_getarchives_where_filter' , 10 , 2 );
remove_filter('getarchives_where' , 'Cpt_getarchives_where_filter' , 10 );
share|improve this answer
Hi Bainternet, thanks for the response. Unfortunately, I'm still getting a 404. – Redlist Apr 5 '11 at 18:47
I'm not seeing 404 at metropoliscreative.com/coding/w/blog/2011/03 for example. and if you do still get 404 then it has noting to do with wp_get_post_type_archive or my answer. – Bainternet Apr 5 '11 at 21:44
My answer is to the question Get monthly archives for custom post type? – Bainternet Apr 5 '11 at 21:45
Your answer was giving me the 404. I've since gotten wp_get_post_type_archive to not 404, however, it just grabs all entries, not ones from the respective month. – Redlist Apr 7 '11 at 16:03
404 means you are not getting to the page so the code i posted as nothing to do with it. also wp_get_post_type_archive can't generate 404 , so that's not the problem. – Bainternet Apr 7 '11 at 17:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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