Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Hey goldenapples, rewriting the permalink structure does the trick. I've posted an example on my blog: http://madpress.org/display-date-in-custom-post-type-permalinks/564/.

This process, and other issues related to custom post type permalinks, are described more fully here.

share|improve this answer
    
Thanks, that seemed to point me in the right direction. If you'd cite or at least link to the source of that example, I'll accept your answer. –  goldenapples Apr 10 '11 at 16:50
    
Date of retrieval: few months ago. Source: some outskirt of the interwebs. Sorry, and good luck! –  MadPress Apr 10 '11 at 23:21
    
So in short, a date based permalink structure + with_front set to true, would allow date based permalinks on custom types to work, there would simply be a lack of date based links to these types without a filter on post_type_link. Shiba's articles are usually quite insightful, stumbled onto those myself a few times now. –  t31os Apr 11 '11 at 12:14
add comment

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.

share|improve this answer
    
I never looked into the endpoint mask rules before - that was an interesting exercise, but unfortunately not what I was looking for. Setting up endpoint masks when you register a post type enables different kinds of archives for that post type (and you can apparently define your own, which is very cool), but it doesn't affect the canonical permalink structure for posts in that post type. –  goldenapples Apr 9 '11 at 23:11
    
When my "listings" were Posts in a special category, their permalink structure was /2011/04/01/post-name. After making them a custom post type, the permalink structure is /listing/post-name. Ideally I'd like something like /listing/2011/04/09/post-name. Not sure if its possible without a lot of work, though. –  goldenapples Apr 9 '11 at 23:12
    
End points should enable you to do that, or at least the trac ticket that discusses end points says as much. –  t31os Apr 10 '11 at 9:44
1  
Apparently setting "with_front" => true enables you to visit a post of a custom post type using any of the structure tags enabled in "permalink_epmask". It doesn't seem to change the canonical permalinks returned with get_permalink(), however. So visiting /listing/2011/04/09/post-name will just redirect to /listing/post-name. –  goldenapples Apr 10 '11 at 16:47
add comment

Your Answer

 
discard

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.