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.

So I created a custom post type like

add_action('init', 'create_post_type');

function create_post_type() {
  register_post_type(
    'portfolio', 
    array(
      'labels' => array(
        'name' => 'Portfolio',
        'add_new_item' => 'Add New Portfolio Item',
        'edit_item' => 'Edit Portfolio Item'
      ),
      'public' => true,
      'capability_type' => 'post',
      'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
      'menu_position' => 5
    )
  );
}

When I add a new custom post (http://localhost/wordpress/portfolio/portfolio-item-3/) and try going to that page, I get a 404. Whats wrong?

UPDATE

This solution works but what does it do and it sounds like its not good to keep flushing my rewrite rules isit?

Add

flush_rewrite_rules();

after you call register_post_type.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

All that does is reset the rewrite rules. You could do the same by visiting the permalinks page and clicking save. You do need to reset them once but not every time. There is no need to flush every time you call register_post_type

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.