Search code examples
phpwordpresscustom-post-typewpml

WPML and custom post types archive template


I am using WPML 3.0.2-a with WordPress 3.8.1

I have a custom post type defined like this:

function add_custom_posts(){
    $args = array(
            'labels' => array(
                    'name' => __( 'Showcases' ),
                    'singular_name' => __( 'Showcases' ),
                    'add_new_item' => __( 'Add New Showcase'),
                    'edit_item' => __( 'Edit Showcases' ),
                    'view_item' => __( 'View Showcase' ),
                    'search_items' => __( 'Search Showcases' ),
                    'not_found' => __( 'No Showcases found.' ),
                    'not_found_in_trash' => __( 'No Showcases found in Trash.' )
            ),
            'public' => true,
            'has_archive' => 'case-studies',
            'menu_position' => 5,
            'taxonomies' => array('post_tag'),
            'supports' => array( 'title', 'thumbnail', 'editor', 'excerpt', 'page-attributes' ),
            'rewrite' => array('slug' => 'case-studies', 'with_front' => false),
            'capability_type' => 'post',
            'hierarchical' => false,
        );

    register_post_type('showcases', $args);

}

add_action( 'init', 'add_custom_posts', 100 );

Visiting a custom post type archive and single post URLs for default language works fine. For example:

/case-studies/ 
/case-studies/%postname%/

are working perfectly and displaying what they should.

However, it doesn't work for the other language:

/de/case-studies/ 
/de/case-studies/%postname%/

are both displaying index.php template of the WordPress theme. It is actualy 404 page but since we don't have 404.php, index.php is used.

Showcases post type is made translatable in WPML settings.

Do you know why is this and how to fix it?


Solution

  • I found out what was the problem.

    The string was not translated under WPML -> String translations

    When I translated it (case-studies -> de/case-studies) it worked.

    Actually, it worked in all variants - both my original code, and code suggested in the answers.