WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'm a bit stuck with getting the custom permalink for custom post type (CPT) archive to work.

I've registered my 'press_release' CPT as following:

add_action('init', 'press_release_post_type_init');
function press_release_post_type_init() {
  $labels = array(
    'name' => _x('Press Releases', 'post type general name'),
    'singular_name' => _x('Press Release', 'post type singular name'),
    'add_new' => _x('Add New', 'Press Release'),
    'add_new_item' => __('Add New Press Release'),
    'edit_item' => __('Edit Press Release'),
    'new_item' => __('New Press Release'),
    'view_item' => __('View Press Release'),
    'search_items' => __('Search Press Releases'),
    'not_found' =>  __('No press release found'),
    'not_found_in_trash' => __('No press release found in Trash'), 
    'parent_item_colon' => ''
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'has_archive' => 'press-release',
    'rewrite' => array('slug' => 'press-release/%year%/%postname%','with_front' => false),
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'show_in_nav_menus' => false,
    'menu_position' => 20,
    'supports' => array(
  register_post_type('press_release', $args);

At the moment if I go to URL http://mysite.press-release then I get to the archive-press_release.php template, which is correct.

However, I would like my CPT archive permalinks to be of the type press-release/%year%

I have tried to specify the above permalink structure when registering CPT:

'has_archive' => 'press-release/%year%'

However, with that permalink structure when I go to http://mysite.press-release or http://mysite.press-release/2011 in both cases I'm redirected to the index.php template not the archive one.

What do I add to make WordPress understand that press-release/%year% permalink with an optional year part are actually the archive templates?

I would really appreciate any help! I'm hoping it's possible to do.

I was planning on constructing my own SQL in the archive-press_release.php to get the records of the correct year.

Many thanks, Dasha

share|improve this question
up vote 0 down vote accepted

Here's the solution:

  1. Install Custom Post Type Archives plugin
  2. Go to Settings->Post Type Archives
    1. Remove the url base option (leave it blank)
    2. Change the template pattern to archive-{POST_TYPE}.php
    3. Tick your custom post type and click save
  3. Rewrite/save your custom permalink structure

Now your links press-release/%year% and press-release/%year%/%month% should work.

share|improve this answer
thanks a lot for the plugin advice! I came across it as well and it works like magic. The archive permalinks for CPT require some fancy rewrite rules... I better learn the rewrite rules properly. Thanks again. – dashaluna Nov 7 '11 at 14:06

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.