WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using WAMP with the latest version of WordPress installed. I have a custom post type created using the following...

function register_fruit() {
register_post_type('fruit', array(
'labels' => array(
'name' => __( 'Fruit' ),
'public' => true,
'has_archive' => true,
'capability_type' => 'post',
'rewrite' => array("slug" => "/fruit", "with_front" => false),
'supports' => array( 'title', 'editor', 'thumbnail'),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
add_action('init', 'register_fruit', 0 );

This works fine when viewing individual items for example..


But if I try and view the archive pages such as...


I get a 404, I can't see where the problem lies, can anyone help?

share|improve this question

Have you tried refreshing permalinks? Settings -> Permalinks (don't have to change anything) Then try again?

share|improve this answer
Yep tried that, still nothing – fightstarr20 Jul 23 '13 at 14:03

Remove the leading slash in your rewrite argument, This:

'rewrite' => array("slug" => "/fruit", "with_front" => false),

should be:

'rewrite' => array("slug" => "fruit", "with_front" => false),

and your archive will work correctly.

share|improve this answer

I have the same issue using:

function cp_init_types() {
register_post_type( 'nursing-home',
        'labels' => array(
            'name' => __( 'Nursing Homes' ),
            'singular_name' => __( 'Nursing Home' )
        'public' => true,
        'has_archive' => true,
        /*'rewrite' => array( 'slug' => 'nursing-homes', 'with_front' => true ),
        'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ),
        'publicly_queryable' => true,
        'exclude_from_search'=> false,
        'taxonomies' => array('category','post_tag'),*/
        'labels' => [
            'name' => __('Locations'),
            'singular_name' => __('Location')
        'public' => true

function add_my_post_types_to_query( $query ) {
if ( is_post_type_archive( "nursing-home" ) && $query->is_main_query() ) {
    $test = $query->get('type');

return $query;

add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
add_action("init", "cp_init_types");

I added the "pre_get_posts" action because I was having the same problem as fightstar.

share|improve this answer
And does that pre_get_posts addition solve the problem? If not, this is not an answer and should not have been posts as one. – s_ha_dum Aug 14 '13 at 0:54

Your Answer


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.