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.

I know that WP 3.1 has added support for archives for custom post types but is there any way to customize the permalinks for them?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Take an example custom post type called movie the code below will create custom permalinks awesomemovies/ regardless of the one created by using the has_archive and rewrite options of register_post_type.

add_filter( 'rewrite_rules_array', 'custom_permalink_for_my_cpt' );
function custom_permalink_for_my_cpt( $rules ) {
    $custom_rules = array();
    // for archive urls
    $custom_rules['awesomemovies/?$'] = 'index.php?post_type=movie';

    // for individual post urls e.g: http://blog.com/awesomemovies/post-name/
    $custom_rules['awesomemovies/([^/]+)/?$'] = 'index.php?post_type=movie&pagename=$matches[1]';
    return $custom_rules + $rules;
}

For more information see WP_Rewrite

share|improve this answer
    
That takes care of the rewrite but doesn't handle the actual creation of permalinks. –  Manny Fleurmond Jun 10 '11 at 19:01
add comment

to customize the permalink of the CPT archive? Check this out http://mark.mcwilliams.me/2010/10/wordpress-3-1-introduces-custom-post-type-archives/

Basically just use the has_archive feature to change the permalink

add_action( 'init', 'mcw_projects_post_type' );

function mcw_projects_post_type() {

    register_post_type( 'projects', array(
        'labels' => array(
            'name' => __('Projects'),
            'singular_name' => __('Project')
            ),
        'public' => true,
        'show_ui' => true,
        'rewrite' => array(
            'slug' => 'project',
            'with_front' => false
            ),
        'has_archive' => true
    ) );

}

Is a way to register a CPT. The has_archive turns on the archive support. Swap that out like:

'has_archive' => 'projects'

Or what have you to adjust the permalink for the CPT archive.

Or are you looking for ways to alter the permalinks with teh CPTs in general? Which is done with the rewrite parameter http://codex.wordpress.org/Function_Reference/register_post_type#Arguments

Not sure which part you are trying to do

share|improve this answer
    
I want to create a more complex permalink for an archive, similar to how this article creates custom permalinks to single pages for post type: shibashake.com/wordpress-theme/… –  Manny Fleurmond Jun 10 '11 at 19:00
1  
show the right start and you can use similar code to adjust the cpt-permalink to what you want. For example, if you wish the permalink to read .../cool-project/... then you need to change the has_archive line to 'has_archive' => 'cool-project' same source: mark.mcwilliams.me/2010/10/… –  Piet Jun 12 '11 at 6:26
    
Right, that's what I say under the block of code above, isn't it? –  Rev. Voodoo Jun 13 '11 at 11:20
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.