Create page via API
Problem
You want to create one or more pages, bypassing the admin interface
Solution
$p = new Page();
$p->setOutputFormatting(false);
$p->template = 'products'; // example template
$p->parent = wire('pages')->get('/'); // example parent
$p->name = "foo"; // example name
$p->title = "My API-generated new PW page";
$p->fieldname = "my field value"; // example field with example value
$p->save();
echo "page ID {$p->id} created!<br>";
Resources
Version
1.0.1
View/correct recipe on GitHub
https://github.com/processwire-recipes/Recipes/blob/master/create-page-via-api.mdAuthor(s)
- dragan