Skip to content

Propagate an entry to a new site via API #13620

Closed Answered by brandonkelly
azerozvn asked this question in Q&A
Discussion options

You must be logged in to vote

Here’s how you can tell the entry to propagate to a new site(s):

use Craft;
use craft\helpers\ElementHelper;

// Get the current supported sites/statuses
$siteStatuses = ElementHelper::siteStatusesForElement($entry);

// Add the new ones
// (set to false if you want the entry to be disabled for the new site)
$siteStatuses[$newSiteId] = true;
// ...

// Save the entry with the new list of supported sites/statuses
$entry->setEnabledForSite($siteStatuses);
Craft::$app->elements->saveElement($entry);

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants