Can /%year%/%monthnum%/%day%/ structure tags be added to custom post type permalinks?

Just wondering if anyone had tried using any of the structure tags available to post permalinks with custom post types… I’m moving my “listings” posts on a site I manage from a category hack under Posts to their own custom post type, but I’d like to still keep some sort of numeric date reference in the permalink structure. How difficult is that to set up?

1 Answer
1

Yes, you should be able to use date based URLs by using the permalink_epmask parameter with your register_post_type call..

add_action('init', 'wpse14370_custom_init');
function wpse14370_custom_init() {
    $args = array(
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'show_in_menu' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true, 
        'hierarchical' => false,
        'menu_position' => null,
        'permalink_epmask' => EP_DATE,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments')
  ); 
  register_post_type('book',$args);
}

Not sure exactly how custom endpoints work, but it’s supported according to the codex page.
http://codex.wordpress.org/Function_Reference/register_post_type

And because it’s not documented, here’s all the possible endpoint values(though i don’t know specifically which are supported with custom post types)..

EP_NONE
EP_PERMALINK
EP_ATTACHMENT
EP_DATE
EP_YEAR
EP_MONTH
EP_DAY
EP_ROOT
EP_COMMENTS
EP_SEARCH
EP_CATEGORIES
EP_TAGS
EP_AUTHORS
EP_PAGES
EP_ALL

If that doesn’t work correctly, maybe just setting with_front to true will be enough if you’re already using date based permalinks.

Leave a Comment