1

I need to have a custom post type slug and its associated taxonomy's slug to have value "archive".

Any other value is ok, I've tested it, so there is no problem with the code per se. I guess the path is already registered in the Wordpress core for the categories archive, so I get a 404 if I try to use that.

Does anybody know a way around it, or can help me understand where to look for the answer?

Code sample for registering custom post type and taxonomy:

// Register Custom Post type
function build_works_post_type() {
$rewrite = array(
    'slug'                       => 'archive/%works%', // THIS is what i need
    'with_front'                 => false,
    'hierarchical'               => true,
);

$args = array(
'labels'            => $labels, // values not relevant in this context
'public'            => true,
'hierarchical'      => true, 
'has_archive'       => true,
'rewrite'           => $rewrite,
'can_export'        => true, 
);
register_post_type('works-index', $args);
}
add_action( 'init', 'build_works_post_type', 0 );
// Register Custom Taxonomy
function build_works_taxonomy() {
$rewrite = array(
    'slug'                       => 'archive', // THIS is what i need
    'with_front'                 => true,
    'hierarchical'               => true,
);
$args = array(
    'labels'                     => $labels, // values not relevant in this context
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => false,
    'query_var'                  => 'works',
    'rewrite'                    => $rewrite
);
register_taxonomy( 'works', 'works-index', $args );
}

add_action( 'init', 'build_works_taxonomy', 0 );

----------------------------

********** UPDATE **********

Turns out it actually works, and you can use "archive" as a custom post type. I just forgot to flush the permalinks, as pointed out here (andreiio answer):

just make sure that, after updating the code, you flush the rewrite rules by visiting Settings > Permalinks. Otherwise you'll still see the old links.

It actually applies every time any slug is changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.