Вопрос

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?

Это было полезно?

Решение 2

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.

Другие советы

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.

I think this will work for you, just missing some action :)

'has_archive' => 'case-studies',

to

'has_archive' => icl_translate('wpml_custom', 'wpml_custom_showcases', 'case-studies'),

THEN

Go to Settings > Permalinks and hit 'Save'.

Let me know if this works perfectly.

Cheers!

have you tried

'has_archive' => true

?

Should work as desired, if I understood correctly.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top