0

I have a CPT called "domaines" (its like vineyards in french). My site have 2 languages (french and english), configured with Polylang for pages and menus translation.

I don't want to use Polylang features for my "domaine" CPT translations to avoid duplicating posts : I want to use ACF for translations (with a condition on the current language inside the template) because there is only 3 fields to translate (and I have more than 1000 posts).

I want an URL like : www.domainame.com/en/domaines/my_slug The www.domainame.com/domaines/my_slug already exists (it's my original post in french).

There is a way to create a "virtual" page on "/en/" with the same content as "/" ?

Thank you

2 Answers 2

0

You can disable the translate of your cpt in polylang and use translated pages to display your cpt posts. In your page template, detect if the current language is english and use your custom translation code to display those translated fields.

I want an URL like : www.domainame.com/en/

You can set it up in the Polylang url settings and hide the default /fr/

[EDIT] To display your cpt in a page template, see this answer. Read the documentation on how to build a custom query.

6
  • It's ok for the /en/ it's already configured like that. But I don't understand what do you want to say "use translated pages" : it's not possible to display a CPT within a page? May 30, 2018 at 12:29
  • sure you can, check out the edit in my answer above.
    – Aurovrata
    May 30, 2018 at 12:52
  • Ok but I don't need to simulate an unique archive but like 1000 singles (with trailing slug) May 30, 2018 at 12:55
  • you can display as many or as little as you want, that all depends on how you build your query.
    – Aurovrata
    May 30, 2018 at 13:00
  • Ok but how can I do with /en/my_page_slug for having /en/my_page_slug/my_single_cpt_slug working? May 30, 2018 at 13:19
0

I've found a (I think) reliable solution to do that:

add_action('init', 'add_my_rewrite_domaines');
function add_my_rewrite_domaines() {
    global $wp_rewrite;
    $wp_rewrite->add_rule('en/vineyards/([^/]+)','index.php?post_type=domaine&domaine=$matches[1]','top');
    $wp_rewrite->add_rule('en/vineyards','index.php?post_type=domaine','top');
    $wp_rewrite->flush_rules();
}

Now I have all my posts, virtually duplicate, without any creation of pages or extra templates.

In Polylang, I've deactivate translations for my 'domain' CPT. Everything works well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.