Skip to main content

Import entries and terms into Statamic

A couple of copy and paste snippets for importing entries and taxonomy terms into Statamic in bulk. Just swap in your own data and handles.

# entries
$items = [
    ['title' => 'Example 1'],
    ['title' => 'Example 2'],
    ['title' => 'Example 3'],
];
foreach ($items as $item) {
    \Statamic\Facades\Entry::make()
        ->published(true)
        ->collection('posts')
        ->blueprint('post')
        ->slug($item['title'])
        ->data($item)
        ->save();
}
# terms
$titles = [
    'Arts',
    'Food & Drink',
    'History',
    'Shopping',
    'Sport',
];
foreach ($titles as $title) {
    \Statamic\Facades\Term::make()
        ->taxonomy('categories')
        ->blueprint('category')
        ->slug($title)
        ->data([
            'title' => $title,
        ])
        ->save();
}