Created
June 22, 2018 01:40
-
-
Save DZuz14/b54b7266b0db39467bf265e0cec4559e to your computer and use it in GitHub Desktop.
Save Craft 3 Entry With PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment