Slug for custom post type archive

I created a new custom post type ‘Projects’ and want the archive of all posts of this type to be available at mysite.com/projects. At the moment all project single posts are shown with a slug as follows mysite.com/projects/project-title, but when I go to mysite.com/projects I get a 404.

Here is how I built the custom post type:

   /* Create the Project Custom Post Type ------------------------------------------*/
 function create_post_type_project() 
 {
$labels = array(
    'name' => __( 'Projects' ),
    'singular_name' => __( 'Project' ),
    'add_new' => __('Add New'),
    'add_new_item' => __('Add New Project'),
    'edit_item' => __('Edit Project'),
    'new_item' => __('New Project'),
    'view_item' => __('View Project'),
    'search_items' => __('Search Project'),
    'not_found' =>  __('No project found'),
    'not_found_in_trash' => __('No project found in Trash'), 
    'parent_item_colon' => ''
  );

  $args = array(
    'labels' => $labels,
    'public' => true,
    'exclude_from_search' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    // Uncomment the following line to change the slug; 
    // You must also save your permalink structure to prevent 404 errors
    'rewrite' => array( 'slug' => 'projects' ),
    'has_archive' => true,
    'supports' => array('title','editor','thumbnail'),

  ); 

  register_post_type(__( 'project' ),$args);
    }

2 Answers
2

Nothing appears to be incorrect – (and I assumed you’ve gone to saved your permalink structure to flush the rewrite rules as the comments suggest? 🙂 ).

I would recommend using this plug-in to determine problems with your url-redirection: http://wordpress.org/extend/plugins/monkeyman-rewrite-analyzer/ – update your question with your findings and someone may be able to offer a solution

However (but this probably isn’t the cause of your issue)., you should not translate the post type’s name, have:

register_post_type('project',$args);

instead of

register_post_type(__( 'project' ),$args);

Translations are for the benefit of the user – and so should be on labels only – the WordPress internal names shouldn’t depend on translation.

Leave a Comment