1

I'm working on a Craft project that has 3 sites. The content for one section is pulled from an API using a console script which runs every 5 minutes.

This has been working fine but I've discovered a bug that the title's aren't being updated across all sites as they are translatable.

This is my current code.

$entry->title = $data->name;
$entry->setFieldValues([
    'body' => $data->text,
    'relatedArticles' => array_map(function($id){
        return [
            'relatedId' => $id,
        ];
    }, $data->related),
    'categories' => array_map(function($cat) {
        return (isset($this->categories[$cat])) ? (int) $this->categories[$cat] : false;
    }, $data->categories),
]);
$success = Craft::$app->elements->saveElement($entry);

All other fields are not translatable so they work fine, Is there a way to propagate the title across all sites or do I need to loop through all the sites to update the entry?

1

Assuming you're on the latest 3.5.x release, then my guess is you need to set the "Title Translation Method" setting for whatever Entry Type you're saving to to "Translate for each site".

enter image description here

1
  • I wasn't aware of this new feature! Thank you, this fixed the issue for me. – Simon Davies Sep 15 '20 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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