url rewriting - Why isn't my custom post type archive URL translating?

admin2025-06-02  2

I've god a 'wine' custom post type, created with rewriting options:

'rewrite' => array(
  'slug' => __('vini', 'fdr'),
  'with_front' => false,
  'pages' => false
),

So the slug should translate. I've got an en-GB.po/mo where I'm translating 'vini' to 'wines'.

Though, the URL generated under translations are not translated:

  • original: [base url]/vini/teroldego-morei/

  • translated: [base url]/en/vini/teroldego-morei/

What I would like (and I guess, should be): [base url]/en/wines/teroldego-morei/

So what? The official docs say 'Should be translatable'. Well, it is, but it seems the whole thing doesn't work.

I've god a 'wine' custom post type, created with rewriting options:

'rewrite' => array(
  'slug' => __('vini', 'fdr'),
  'with_front' => false,
  'pages' => false
),

So the slug should translate. I've got an en-GB.po/mo where I'm translating 'vini' to 'wines'.

Though, the URL generated under translations are not translated:

  • original: [base url]/vini/teroldego-morei/

  • translated: [base url]/en/vini/teroldego-morei/

What I would like (and I guess, should be): [base url]/en/wines/teroldego-morei/

So what? The official docs say 'Should be translatable'. Well, it is, but it seems the whole thing doesn't work.

Share Improve this question edited Jul 26, 2017 at 11:56 Max Yudin 6,3982 gold badges26 silver badges36 bronze badges asked Jul 26, 2017 at 9:58 Luca ReghellinLuca Reghellin 1,6522 gold badges21 silver badges45 bronze badges 2
  • Are you sure that you get the right string from your po/mo files? I would echo that somewhere to check. Just an idea, may you are sure about it. – Luckyfella Commented Jul 26, 2017 at 11:50
  • Also, flush rewrite rules every time you change something regarding them. Go to Settings -> Permalinks and click Save without changing anything. – Max Yudin Commented Jul 26, 2017 at 11:58
Add a comment  | 

1 Answer 1

Reset to default 0

UPDATE 1:

I haven't find a solution yet (other than using Polylang Pro). But I must add that my original question was partially wrong, since the rewrite option is for the single page url, not the archive one.

Custom post type archive has its own slug and it's the has_archive option (can be boolean or string). So basically can be something like this:

'has_archive' => __('products','mytxtdomain')

Though, just as the rewrite url, it doesn't work, and probably the answer below is still valid.


The answer is: it's not possible.

Falks or the Polylang Pro crew explained me the reason why:

If you flush your rewrite rules while the locale is Italian, your slug is evaluated to 'vini'. If you flush them while the locale is English, the slug is evaluated to 'wine'. So, in the first case, the rewrite rule pattern is:

vini/([^/]+)(?:/([0-9]+))?/?$

and in the second case, it is

wine/([^/]+)(?:/([0-9]+))?/?$

But you never have both at the same time. So only one is working.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748820186a313996.html

最新回复(0)