This is my code:

$giveaway = Craft::$app->globals->getSetByHandle('promotions');
$giveaway->giveawayName = "New Name";
$success = Craft::$app->globals->saveSet($giveaway);

Controller returns true, but no changes have been made to the "promotions" global set. What have I missed?

  • saveSet will save the Global's settings/fields. See here to save content.
    – Oli
    Jan 7 '20 at 16:26

Oli’s comment is mostly right, but I think the solution is event simpler—the method you discovered is specifically for saving the GlobalSet settings/definition (like its name, handle, and the fields it uses), but what you're looking for is a more generic method for saving the Element that contains the actual content (as though you were updating it from the main Globals menu in the CP):

// Generic save method for any Element type, including Globals:


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.