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?
You can simply create and assign custom page templates for your custom post type in your custom plugin. Just create 2 template file - single-{post_type}. php and archive-{post_type}.
Let's start by adding the Posts block to display items from your custom post type. Simply drag and drop the Posts block in the Advanced section onto your page. By default, the posts block will display your blog posts. Click on the block settings and then select your post type under Query by Post Type section.
Tap or your profile picture in the bottom right to go to your profile. Tap the post you'd like to archive. Tap in the top right. Select Archive.
If you mean that the default language will be on the main domain and the translation will be on another domain, then no need to use a WordPress Multisite installation. After that is done, you can enable the "Different domain per language" option in WPML settings and add the new domain there.
I found this support thread where they say that one should change the following line (in your code):
'has_archive' => 'case-studies',
to:
'has_archive' => icl_translate('wpml_custom', 'wpml_custom_showcases', 'case-studies'),
Might be a good idea to ask the official support for this, as it's commercial software and no documentation is available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With