Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $section = Craft::$app->sections->getSectionByHandle('journalArticles');
- $entryTypes = $section->getEntryTypes();
- $entryType = reset($entryTypes);
- $entry = new Entry([
- 'sectionId' => $section->id,
- 'typeId' => $entryType->id,
- 'fieldLayoutId' => $entryType->fieldLayoutId,
- 'authorId' => 1,
- 'title' => 'My Entry',
- 'slug' => 'my-entry',
- 'postDate' => new DateTime(),
- ]);
- $entry->setFieldValues([
- 'journalTitle' => 'Hello'
- ]);
- $success = Craft::$app->elements->saveElement($entry);
- if(!$success) {
- echo "why";
- }
Add Comment
Please, Sign In to add comment