I'm trying to create a new Entry via PHP, with custom fields (Craft 3). I can save it, however my custom fields don't appear. I've tried using setFieldValue
, as well as $entry->excerpt = 'Lorem...';
, however neither work.
My code is below, using craft\elements\Entry
:
$entry = new Entry();
$entry->sectionId = 4;
$entry->typeId = 4;
$entry->authorId = 1;
$id = uniqid('product_');
$entry->title = $id;
$entry->slug = $id;
$entry->setFieldValue('excerpt', 'Lorem...');
if(Craft::$app->elements->saveElement($entry)) {
return $entry;
} else {
throw new \Exception("Couldn't save new bespoke product: " . print_r($entry->getErrors(), true));
}