Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Post Types display only 404 WordPress

  • SOLVED

All custom post types on a client's website are now displaying 404 errors. All plugins have been deactivated, and we have changed the permalinks structure every which way. Nothing is working. Can you help solve the issue?

Here are the details:
- This is the main site of a MultiSite install running the 3.0.1
- Site runs the "remove /blog/" plugin (http://thinkinginwordpress.com/)
- Permalink structure: /archives/%postname%
- custom post type permalink should be /%customposttype%/%postname%

The Custom Post Type
add_action( 'init', 'register_cpt_faqs' );
function register_cpt_faqs() {
register_post_type( 'faqs',
array(
'labels' => array(
'name' => __( 'FAQs' ),
'singular_name' => __( 'FAQ' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New FAQ' ),
'edit' => __( 'Edit' ),
'edit_item' => __( 'Edit FAQ' ),
'new_item' => __( 'New FAQ' ),
'view' => __( 'View FAQ' ),
'view_item' => __( 'View FAQ' ),
'searemperor_items' => __( 'Search FAQs' ),
'not_found' => __( 'No FAQs found' ),
'not_found_in_trash' => __( 'No FAQs found in Trash' ),
'parent' => __( 'Parent FAQ' ),
),
'public' => true,
'show_ui' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 20,
'hierarchical' => false,
'query_var' => true,
'supports' => array( 'title', 'editor', ),
'rewrite' => array( 'slug' => 'faqs', 'with_front' => false ),
'taxonomies' => array('faqtags' ),
'can_export' => true,
)
);
}

add_action( 'init', 'register_taxonomy_faq', 0 );
function register_taxonomy_faq() {
register_taxonomy( 'faqtags',
array( 'faqs' ),
array(
'public' => true,
'show_ui' => true,
'show_tagcloud' => true,
'show_in_nav_menus' => true,
'hierarchical' => false,
'labels' => array(
'name' => __( 'FAQ tags' ),
'singular_name' => __( 'FAQ tag' ),
'searemperor_items' => __( 'Search FAQ tags' ),
'popular_items' => __( 'Popular FAQ tags' ),
'all_items' => __( 'All FAQ tags' ),
'parent_item' => __( 'Parent FAQ tag' ),
'parent_item_colon' => __( 'Parent FAQ tag:' ),
'edit_item' => __( 'Edit FAQ tag' ),
'update_item' => __( 'Update FAQ tag' ),
'add_new_item' => __( 'Add New FAQ tag' ),
'new_item_name' => __( 'New FAQ tag' ),
),
'query_var' => 'faqtags',
'rewrite' => array( 'slug' => 'faqtags', 'with_front' => true ),
)
);
}


The htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

Answers (7)

2010-08-25

Michelle Dancer answers:

Do the links work correctly with default permalink structure, but 404 when you change it? If so I had a similar problem and the way I found to finally fix it was to add:

flush_rewrite_rules( false );

just before the closing tag of my custom post types function, in your case register_cpt_faqs().

After that reset the permalinks for good measure and fingers crossed it'll work for you too.


Matt Taylor comments:

That was what I was missing. Thanks!

2010-08-25

Utkarsh Kukreti answers:

Have you tried resaving the Permalinks from Settings?


Matt Taylor comments:

Yes, of course.

2010-08-25

Milan Petrovic answers:

Try my plugin GD Custom Posts And Taxonomies Tools:

free version: http://wordpress.org/extend/plugins/gd-taxonomies-tools/
pro version: http://dv4p.com/gdtt

It's made to ensure that everything is registered properly, rewrite rules flushed when needed and more. It's easy to make mistake and waste days in finding problems if you code everything manually like you did.


Matt Taylor comments:

Thanks Milan but we are looking for a plugin-free solution.

2010-08-25

Patrick Daly answers:

I doubt this is causing the issue, but your htaccess has duplicate lines. Delete the last two. In fact, I'd just delete the whole thing and re-save your permalink structure.


Patrick Daly comments:

Add those functions to the Twenty Ten theme and see if it works.


Matt Taylor comments:

Adding the code exactly in TwentyTen still produces a 404.


Patrick Daly comments:

I just setup a test install, copied and pasted your code into the Twenty Ten functions.php, changed the permalinks to /archives/%postname%/ and the result: http://test.clients.developdaly.com/faqs/test/

So it works for me. My htaccess ended up being:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]


You might also try leaving your permalinks default, like so: http://test.clients.developdaly.com/?faqs=test

If you've done everything above then maybe your WordPress install is broken or you've got some funky server settings.

2010-08-25

Stephanie Leary answers:

Ethan, is your type/taxonomy code in a plugin file or functions.php? If it's in a plugin, try adding an activation hook so the rewrite rules get flushed just once, like this:

register_activation_hook( __FILE__, 'activate_faq_post_types' );

function activate_faq_post_types() {
register_cpt_faqs();
register_taxonomy_faq()
$GLOBALS['wp_rewrite']->flush_rules();
}


Matt Taylor comments:

Its in the functions file. But thanks. :)

2010-08-25

Baki Goxhaj answers:

Dublicate your <strong>single.php</strong> or or <strong>index.php</strong> into <strong>single-faqs.php</strong> - this is how you show the posts of your custom post type on single view. After that you can do your changes accordingly.

I would like to help you on-site, if you cannot solve this alone.


Matt Taylor comments:

Thanks Baki. That too though has already been done.


Baki Goxhaj comments:

Can I have a look on-site? banago-at-gmail.com

2010-08-25

Michael Fields answers:

Delete this line:

'rewrite' => array( 'slug' => 'faqs', 'with_front' => false ),