Jump to content

Problems with 'active' in imported pages via API


joe_g
 Share

Recommended Posts

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

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:

  1. 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'.
  2. 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

@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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...