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 7 replies, has 3 voices.

Last updated by jean-marie 2 months ago.

Assigned support staff: Bruno Kos.

Author Posts
July 17, 2019 at 3:09 pm #4231543

Rémi

Hello,

I have the exact same issue as described here:
https://wpml.org/forums/topic/how-to-translate-dynamic-slugs-on-custom-post-types/

I am using dynamic rewrite rules to have my CPT taxonomies in URL.

Using:

'rewrite' => array(
            'slug'          => _x('boutiques/%shop_category%', 'slug boutique', 'mydomain'),
            'with_front'    => false
)

And:

function my_generate_taxonomy_rewrite_rules($wp_rewrite) {
    $rules = array();
    $post_types = array(
        'shop' => array(
            'taxonomy' => 'shop_category',
            'slug'     => _x('boutiques', 'slug categorie boutique', 'mydomain')
        ),
        'event' => array(
            'taxonomy' => 'event_category',
            'slug'     => _x('evenements', 'slug categorie évènement', 'mydomain')
        ),
        'offer' => array(
            'taxonomy' => 'offer_category',
            'slug'     => _x('offres', 'slug categorie offre', 'mydomain')
        )
    );
    foreach($post_types as $post_type => $settings) {
        $terms = get_categories(array(
            'type'          => $post_type,
            'taxonomy'      => $settings['taxonomy'],
            'hide_empty'    => 0
        ));
        foreach($terms as $term) {
            $rules[$settings['slug'] . '/' . $term->slug . '/?$'] = 'index.php?' . $settings['taxonomy'] .
                '=' . $term->slug;
            $rules[$settings['slug'] . '/' . $term->slug . '/page/?([0-9]{1,})/?$'] = 'index.php?' .
                $settings['taxonomy'] . '=' . $term->slug . '&paged=' . $wp_rewrite->preg_index(1);
        }
    }
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'my_generate_taxonomy_rewrite_rules', 10, 1);

This works great in original language, but in other languages, it send 404 for archive page, category page, single page... (with slugs translated and permalinks flushed)

In the other topic it is said that:
"It looks like you are adding a rewrite rule and that is currently not working with WPMl but will be fixed in future versions."

WPML is up-to-date, and it seems there is still this issue.

Thanks

July 18, 2019 at 6:11 am #4235163

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

Thank you for contacting WPML support!

I checked internal documentation and I did not get the impression that the solution has been implemented into WPML. But we have published an errata on this. Can you check this and tell me if it helps you:
https://wpml.org/errata/wpml-redirection-and-issues-with-custom-rewrite-rules/

Regards,
Bruno Kos

July 18, 2019 at 10:22 am #4237421

Rémi

Hi Bruno,

Yes I already tried that, it doesn't work: the wpml_is_redirected filter is not triggered at all (tested with a die() at the beginning of the function).

July 18, 2019 at 12:29 pm #4238689

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I have asked our 2nd tier for an opinion, hopefully they can shed more light on this.

I will get back to you as soon as I hear from them!

Regards,
Bruno Kos

July 19, 2019 at 12:47 pm #4246519

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

/actualite/%category%/%postname%/. As a test, can you perhaps try to remove /actualite/ from permalink?

We have no other suggestions at this point and this will need to be escalated. Can you tell me if you can create a Duplicator package perhaps or if I provide you with clean sandbox installation where you could add your code, and I will send this example to our team for further investigations?

Let me know which of these options will work for you - I have set your next reply as private, you can add the duplicator link inside.

Regards,
Bruno Kos

July 22, 2019 at 6:04 am #4254115

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

This has been escalated to our 2nd tier team and may take some debugging time, I'll get back to you as soon as I have any news or questions for you.

Regards,
Bruno Kos

August 12, 2019 at 5:53 am #4378471

Bruno Kos
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hi,

I have new from our 2nd tier about this. From what we understand, you want to have a URL structure like this:
"website.com/%post-type-slug%/%taxonomy-term-slug%/%single-post-slug%"
or
website.com/boutiques/automobile/clean-cars/
Is that correct? If so, perhaps creating custom rewrites is not the best way to achieve this result.

We removed the rewrite rules then tried this tutorial with the "boutiques" post type and it worked better (no more 404 errors on the pages). We created a cloudways site with the fix:
hidden link

hidden link
hidden link
hidden link
hidden link
(login: admin / password: otgs)

There is a issue with the language switcher on the single pages (when you try to change from french to english language), but it may be related to a different issue.

From our point of view, you want to change the default WordPress URL structure, but do this in a way that is WPML compliant, so we see this a custom work that would require help from our Contractors perhaps:
https://wpml.org/contractors/

Regards,
Bruno Kos

September 6, 2019 at 9:11 am #4524245

jean-marie

Hello Bruno,

I'm the dev who continues the project Rémi.
Your solution hasn't been implemented yet. Would it be possible to access the hidden links of the last answer?

Thank you very much,
Thomas