Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 540
Aleksandar Jakovljevic Avatar asked Feb 07 '14 15:02

Aleksandar Jakovljevic


People also ask

Can I assign a template to a custom post type?

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}.

How do I create a custom archive page for custom post type in WordPress?

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.

How do I create an archive post?

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.

Does WPML need multisite?

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.


1 Answers

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.

like image 168
Fleshgrinder Avatar answered Sep 28 '22 01:09

Fleshgrinder