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 dont know why my custom post types render the Page not found. This is the code I am using to register custom posts.

www.example.com/products/product1/ renders 404 where as www.example.com/?products=product1 is perfectly fine.

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type('products', array(
        'label' => __('Products'),
        'singular_label' => __('Product'),
        'public' => true,
        'show_ui' => true, // UI in admin panel
        '_builtin' => false, // It's a custom post type, not built in!
        '_edit_link' => 'post.php?post=%d',
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array("slug" => "products"), // Permalinks format
        'supports' => array('title','author')
    ));
}
share|improve this question
    
You need to flush your rewrite rules, one way is to visit the permalink page under settings and the other way is to call flush_rewrite_rules(). If you are shipping the above code with theme/plugin then you need to flush the rules on activation. –  Hameedullah Khan May 15 '11 at 6:05
add comment

3 Answers

Yea, you need to flush the permalinks.

This helps solve the problem even further.

    'rewrite' => array("slug" => "products"), // Permalinks format

I was getting the same problem when using

'rewrite' => true,
share|improve this answer
    
+1 yeah I figured this out too.. lol –  Atif Mohammed Ameenuddin May 19 '11 at 5:24
add comment

Have you refreshed your rewrite rules? You can do this by resaving your permalink settings under Settings>Permalinks in the admin.

If it is a plugin or theme you are distributing you can call $wp_rewrite->flush_rules(); upon activation.

share|improve this answer
    
Didnt knew about flush_rules(); –  Atif Mohammed Ameenuddin May 16 '11 at 6:15
add comment
  1. Go to Settings > Permalinks
  2. Change your permalinks to something different to what you actually have
  3. click on “Save changes”
  4. Change your permalinks back to your preferred setting
  5. relaod the Page.

hope that can help you

share|improve this answer
3  
You don't need to change and re-save permalink settings, simply visiting the permalinks settings page flushes the rewrite rules without having to change anything. –  Milo Feb 13 '13 at 15:36
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.