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've been banging my head against my iMac trying to figure out what's wrong. I've also trolled these archives and have tried the following things to fix:

  • flush permalinks
  • remove possibly conflicting categories/slugs
  • flush_rewrite_rules( false );
  • 'has_archive' => true, 'has_archive' => false (as well as many similar $args variations
  • archive-{CPT}.php, archive-{CPTSlug}.php
  • category-{CPT}.php, category-{CPTSlug}.php
  • content-{CPT}.php, content-{CPTSlug}.php
  • {CPT}-archive.php, {CPTSlug}-archive.php
  • change the slugs of the CPT and taxonomies and flushed permalinks

ALL attempts return a 404 page when visiting www.site.com/CPTSlug or www.site.com/CPT. The individual posts of the CPT however, display correctly at the URL www.site.com/CPTSlug/post_title.

When I had these set as categories instead of custom post types it worked perfectly. If anyone out there can spot the problem I would be most grateful.

function register_artists_post_type() {
    register_post_type('artists',array(
        'labels' => array(
                'name' => __( 'Artists' ),
                'singular_name' => __( 'Artist' ),
                'add_new' => __( 'Add Artist','Artist' ),
                'add_new_item' => __( 'Add New Artist' ),
                'edit_item' => __( 'Edit Artist' ),
                'new_item' => __( 'New Artist' ),
                'view_item' => __( 'View Artist' ),
                'search_items' => __( 'Search Artists' ),
                'not_found' => __( 'No Artists Found' ),
                'not_found_in_trash' => __( 'No Artists In Trash' ),
                'parent_item_colon' => ''
            ),
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'has_archive' => true,
        'supports' => array( 'title','editor','excerpt','custom-fields','thumbnail' ),
        'rewrite' => array('slug' => 'artists'),
        'taxonomies' => array('large_feature','small_feature'),
        'capability_type' => 'post',
        'hierarchical' => false,
    ));
}
add_action('init','register_artists_post_type');

There were previously categories called "Artists" (slug = artists) as well as child categories with slugs of large_feature and small_feature. Those have all been deleted from the database and have been replaced with the custom post type below and the slugs you see in the registration.

The theme files are as follows (though I don't think this is the problem since it's a 404 page displayed, but in the interest of giving as much relevant information as possible...)

archive.php archive_{cpt}.php category.php single.php single_{cpt}.php

The single posts are correctly posting using single_{cpt}.php. Archives however, are not.

share|improve this question
add comment

3 Answers 3

You can always try to filter rewrite_urls array and create rules for you custom post type.

share|improve this answer
3  
Can you provide an example of how to do that? –  Chip Bennett Nov 13 '12 at 21:49
    
On that line of thought, I changed 'rewrite' => array('slug' => 'artists') to 'rewrite' => true and flushed the permalinks. That at least got it to come up as site.com/cpt/ which is a start. So I changed it back to 'rewrite' => array('slug' => 'artists') and now it's coming up as site.com/artists/ but it's not using the archive template or archive.php. I'm in the process now of trying to figure out what file it's using, but I have body text in all the docs saying what the filename is and I don't see that anywhere on the page. Strange. –  Kristina Childs Nov 13 '12 at 22:00
    
add_filter('rewrite_rules_array', 'rewrite_rules_array_custom'); function rewrite_rules_array_custom($_rules){ $rules = array(); foreach($_rules as $key=>$rule){ if (strpos($key, 'artists') !== false){ if (!isset($rulesSetted)){ $rulesSetted = true; $rules['artists/([^/]+).html?$'] = 'index.php?post_type=artists&artists=$matches[2]&paged=1'; } } else { $rules[$key] = $rule; } } return $rules; } –  Oleg Butuzov Nov 13 '12 at 22:00
1  
Please add code to the answer, comments are unsuitable for it. –  Rarst Nov 13 '12 at 22:06
    
i am sorry for that. tried to edit but can't do that more in 5 minutes.. pastebin.com/Tme0W7DJ this is a sample of rewrites_rules_array filter. jsut a sample. you need to palce correct hook inside and palce your own rules. it helps to create miracles but require a lot of testing. i am actualy writing test case each time while do such things. you also can use var_dump function to see whats inside of the array that you get... and change it as you wish =) –  Oleg Butuzov Nov 13 '12 at 22:11
show 3 more comments
'hierarchical' => false,
));

Try removing the comma after this. It has to be throwing an error on that.

share|improve this answer
    
that didn't work :( –  Kristina Childs Nov 13 '12 at 21:46
add comment
up vote 0 down vote accepted

There aren't any golden answers to this problem, but for the sake of closing this thing out, I did get it fixed.

For anyone else having this problem. I would highly suggest making a wordpress sandbox and building it out in a fresh install. I did that and it worked perfectly. The frustrating thing is, after adding back all the functions and plugins one by one, I never ran into the same problem, even though I was working with the exact same database, the exact same plugins, the exact same template files and the exact same functions within functions.php.

The only difference is that I had been basing my theme off Twenty Eleven and this time I went with Starkers, a bare-bones theme intended for theme developers. So it had to have been something native to Twenty Eleven that was conflicting. What conflicted will sadly remain a mystery.

share|improve this answer
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.