Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 11 replies, has 2 voices.

Last updated by Joel 6 years, 6 months ago.

Assigned support staff: Bruno.

Author Posts
December 11, 2014 at 3:48 pm #527127

Joel

I am translating a custom post type created by my own in my functions.php file.
My site in initially created in french, and I added english language, with folder-formated URL (mysite.com for french, mysite.dom/en/ for english)

Then, in WPML traduction options settings, I made my Custom Post Type translatable.

When I save a content of my Custom Post Type in english, its URL do not reflect the folder structure of URL. So visiting my content, I get a 404 error, until I manually prefix the URL with /en.

URL generated on native WordPress post types (posts and pages) are all good. My problem is only concerning a Custom Post Type.

Did I missed a parameter somewhere ?

December 12, 2014 at 1:23 am #527316

Bruno

Please, could you add the code you are using, so I can test it on my test environment? If the code is too long, please use the pastebin.com.

Also, what is the URL of your website?

Thank you.

December 12, 2014 at 8:37 am #527403

Joel

Hi,

Sorry, I juste double-checked my (old) code. It uses this code

$args = array(
        'labels' => array(
            'name' => __('Liste des produits'),
            'all_items' => __('Liste des produits'),
            'singular_name' => __('Produit'),
            'add_new' => __('Ajouter un produit'),
            'add_new_item' => __('Ajouter un produit'),
            'edit_item' => __('Modifier le produit'),
            'new_item' => __('Nouveau produit'),
            'view_item' => __('Voir le produit'),
            'search_items' => __('Chercher des produits'),
            'not_found' => __('Aucun produit trouvé'),
            'not_found_in_trash' => __('Aucun produit dans la poubelle'),
            'menu_name' => __('Produits')
        ),
        'hierarchical' => true,
        'description' => 'Produits Guyon',
        'supports' => array('title', 'editor', 'page-attributes'),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => false,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'page',
        'rewrite' => false,
        'suppress_filters' => true
    );
    register_post_type('produit', $args);

    // Rewriting pour les produits
    global $wp_rewrite;
    $queryarg = 'post_type=produit&p=';
    $wp_rewrite->add_rewrite_tag('%cpt_id%', '([^/]+)', $queryarg);
    $wp_rewrite->add_permastruct('produit', '/produit/%cpt_id%/%postname%/', false);

I guess the problam comes from add_permastruct() fucntion. Is there a way to declare a permalink structure respecting the 'one folder per language' URL format ?

December 12, 2014 at 7:41 pm #527861

Bruno

I tested your code and it seems that has an error. The URL for me is:

hidden link

Note that the %cpt_id% is not being converted. Also, note that the language is being added to URL correctly.

I'll ask for some information so I can verify the problem. The fields for you to insert the credentials will be below its comment field.

Please let me know exactly what steps should I follow to see the problem.

Note: Please make a full backup of your site.

Thank you.

December 16, 2014 at 12:22 am #528992

Bruno

I saw the problem. That seems a little strange.

Please as a test, could you disable all non-WPML plugins and see if the problem persists?

Thank you.

December 16, 2014 at 3:07 pm #529522

Joel

Hi,

I just deactivated all the plugins but WPML.
The problem persists : permalink generated for a brand new 'product' is wrong and leading to a 404 page.
Thanks

December 17, 2014 at 12:50 am #529843

Bruno

Please, can I install the Duplicator plugin ( https://wordpress.org/plugins/duplicator/ ) to make a copy of your site and install it on my test environment? This will help me debug the problem.

Thank you.

December 18, 2014 at 9:02 am #530733

Joel

Hi,

Yes, you can install ths plugin.

December 18, 2014 at 9:16 pm #531188

Bruno

I installed Duplicator, but when I try to create a copy, this error message is displayed:

--------------------
Duplicator > Paquets > Créer Paquet

Version de PHP [5.3.10] Pass
Archivage Zip Activé Fail
Mode Sécurité Désactivé Pass
Fonction file_get_contents Pass
Fonction file_put_contents Pass

PHP dans ses versions 5.2.17 ou supérieures est nécessaire. La logique de versioning de PHP fonctionne de telle façon que 5.2.9 est inférieur à 5.2.17. Pour que la compression soit activée, l'extension ZipArchive de PHP est requise. Le mode sécurité (Safe Mode) doit être désactivé (Off) dans votre fichier php.ini ; cette fonction n'est plus supportée après PHP 5.3.0. En cas de problèmes avec cette section, merci de contacter votre hébergeur ou administrateur système. Pour plus d'informations, veuillez vous reporter à notre documentation en ligne.
--------------------

It seems that the ZipArchive PHP extension is not installed/enabled.

Please could you check with your host?

Thank you.

December 19, 2014 at 2:47 pm #531716

Joel

Hi, I just enabled Zip module.
Can you retry the process please ?

December 20, 2014 at 1:04 pm #532083

Bruno

Sorry for the delay.

I fixed your site. I did two changes in the functions.php file of your theme:

+++ functions.php	2014-12-20 10:50:10.558555781 -0200
--- functions.php	2014-12-20 10:24:22.994573171 -0200
@@ -75,7 +75,7 @@
     global $wp_rewrite;
     $queryarg = 'post_type=produit&p=';
     $wp_rewrite->add_rewrite_tag('%cpt_id%', '([^/]+)', $queryarg);
-    $wp_rewrite->add_permastruct('produit', '/produit/%cpt_id%/%postname%/', false);
+    $wp_rewrite->add_permastruct('produit', 'produit/%cpt_id%/%postname%/', false);
 
     // CPT Familles de produit
     $args = array(
@@ -216,8 +216,8 @@
     $newlink = $wp_rewrite->get_extra_permastruct('produit');
     $newlink = str_replace("%cpt_id%", $post->ID, $newlink);
     $newlink = str_replace("%postname%", $post->post_name, $newlink);
-    $newlink = home_url(user_trailingslashit($newlink));
-    return $newlink;
+    //$newlink = home_url(user_trailingslashit($newlink));
+    return home_url('/') . $newlink;
 }

Please could you check if it is working as desired?

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Thank you.

December 22, 2014 at 9:03 am #532442

Joel

Wow, thank you for your amazing support. It seems working now.
I will now reactivate plugins.
Thanks again.