joe_g Posted February 5, 2024 Share Posted February 5, 2024 Hi there, I've got a site with 12 languages. When I create a page in the backend all languages are active by default, great. However, when I create a page via the api NO languages are active, except the default language. Why is that? And, how can I make sure everything is active all the time? I tried this piece of code to make all language active in a recently imported page... foreach($languages as $lang) { if($lang->isDefault()) continue; $p->set("status$lang", 1); $p->save(); } ...but it messes up the data. I've got a repeater matrix where the content gets repeated 12 times with the code above. I'm not sure why it interferes with the repeater matrix Is there a safe, non-destructive way to make sure all languages are always active? Link to comment Share on other sites More sharing options...
joe_g Posted February 5, 2024 Author Share Posted February 5, 2024 Or perhaps, my whole approach is wrong and i should rely on active for translated pages instead. Maybe that's better, but then I don't know this: If I would want to make a language switcher for a specific page, how do I loop through all active translations? I can't find a selector for 'active'. How can i specify a redirect to the default language instead getting a 404 for a page with a missing language? many thanks J Link to comment Share on other sites More sharing options...
ngrmm Posted February 8, 2024 Share Posted February 8, 2024 @joe_g Please check if you have any typing errors. I also have a repeater matrix and it works for me. foreach ($wire->languages as $lang) { $page->set("status$lang", 1); } $page->save(); 1. You could check if status$lang is 1 2. If there is no translation, PW automatically views the default content. But you could also check for translations an do a redirect Link to comment Share on other sites More sharing options...
poljpocket Posted February 11, 2024 Share Posted February 11, 2024 You can refer to my issue report a few months back where @ryan answered why your exact issue is as it is, and likely won't get changed: Language status fields defaults inconsistency in admin vs API · Issue #1826 · processwire/processwire-issues (github.com) 1 Link to comment Share on other sites More sharing options...
joe_g Posted February 13, 2024 Author Share Posted February 13, 2024 Thanks both! I'll try and have a look if I made some mistake. I know I had a similar code that set active to everything globally, and that worked without problems. So perhaps it's when I create new pages, somehow. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now