Custom Permalinks for Custom post Type Archives?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x