1

I'm having a bit of a problem with my custom post types... My post type is called 'videos'. I have all of the posts showing on their single page using the 'single.php' template. But when I take the post name out of the url and keep /videos/, I get a 404 - but I want to list all of the 'videos' here. I tried using archive-videos.php file as the codex reccomends: http://codex.wordpress.org/Post_Types, still with no luck. It also says you can do single-videos.php for custom post types, but this doesn't work either. I'll display the code I use to register my post type below, am I doing something wrong?

add_action('init', 'videos_register');
function videos_register() {
    $labels = array(
        'name' => _x('Videos', 'post type general name'),
        'singular_name' => _x('Video', 'post type singular name'),
        'add_new' => _x('Add New', 'question'),
        'add_new_item' => __('Add New Video'),
        'edit_item' => __('Edit Video'),
        'new_item' => __('New Video'),
        'view_item' => __('View Video'),
        'search_items' => __('Search Videos'),
        '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' => get_stylesheet_directory_uri() . '/article16.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail')
      ); 
    register_post_type( 'videos' , $args );
    flush_rewrite_rules();
}
3

You need to add the arg 'has_archive' => true. Hope this helps!

  • Damn... as easy as that. Much appreciated! – Henryz Sep 21 '11 at 10:46
2

I was also getting a 404 error when attempting to reference the custom post archives. The following lines solved my problems:

...
'rewrite' => true,
'has_archive' => true
...    
register_post_type( 'post_type' , $args );    
flush_rewrite_rules();

I also had to make sure my permalink structure was:

/%postname%/
0

i also found this link as an alternative http://en.bainternet.info/2011/custom-post-type-getting-404-on-permalinks

0

Bit late may be but important to mention that …

'has_archive' => 'my-example-archive' // True/False 

… or explicitly mentioning the slug i.e news, events etc and than disable the permalinks and again reactive after saving will solve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.