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 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..

www.mydomain.com/fruit/apple
www.mydomain.com/fruit/orange
www.mydomain.com/fruit/pear

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

www.mydomain.com/fruit

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

share|improve this question
add comment

3 Answers

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
add comment

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
add comment

I have the same issue using:

function cp_init_types() {
register_post_type( 'nursing-home',
    array(
        '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'),*/
    )
);
/*register_taxonomy('location','nursing-home',[
        '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() ) {
    $query->set('type',"nursing-home");
    $test = $query->get('type');
    var_dump($test);
}

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
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.