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.

When using custom post types I reach a dilemma where I have to use flush_rewrite_rules(); when using a permalink structure, otherwise it goes to a 404. After using it It works on one CPT but if you have 2 or 3, I still have the same problem and have to back to the basic permalink settting. If you could help me, that would be great.

add_action('init', 'video_register');

function video_register() {

$labels = array(
    'name' => _x('Video', 'post type general name'),
    'singular_name' => _x('Video', 'post type singular name'),
    'add_new' => _x('Add New', 'Video'),
    'add_new_item' => __('Add New Video'),
    'edit_item' => __('Edit Video'),
    'new_item' => __('New Video'),
    'view_item' => __('View Video'),
    'search_items' => __('Search Video'),
    'not_found' =>  __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon' => ''
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'menu_icon' => null,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'taxonomies' => array('post_tag'),
    'supports' => array('title','editor','thumbnail','custom-fields',   'comments',)

       ); 

register_post_type( 'video' , $args );
flush_rewrite_rules();
}

This is what I'm adding for my custom post type. Thank you.

share|improve this question
add comment

1 Answer

Do not use flush_rewrite_rules() on every init, use it in your plugin’s activation hook once (example).

Side note: __('New Video') is broken. Without the second parameter textdomain this text is not translatable. Use __( 'New Video', 'your_plugin_textdomain' ) instead.

share|improve this answer
    
Is it possible that you could give me a link that goes more in depth about what you are saying. Im new to this, Thank you. –  Eric Jan 21 '13 at 4:14
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.