How would you recommend creating two pages or more using CLI, including custom fields (summary, body, sidebar, etc.)?
I tried creating two+ pages using an array - the first page is correct, but the following pages fail. only the Name field is set, other fields are ignored / not set - I suspect this happens because the $wire object is destroyed somehow when I loop the array- no error message is displayed. Here is one variant of the code I have used:
$url_parent = "/myparent/";
$template = "basic-page";
$data = array(
array('title'=>'Foo title', 'body'=>'Text for foo.', 'name'=>'foo' ),
array('title'=>'Bar title', 'body'=>'Text for bar.', 'name'=>'bar' ),
);
foreach($data as $v) {
// Get page object.
$p = $wire->pages->get($url_parent . $v['name'] );
if(!$p->id) {
$p = new Page();
$p->template = $template;
$p->parent = $url_parent;
$p->name = $v['name'];
}
$p->of(false);
foreach($v as $kk=>$vv) {
$p->{$kk} = $vv;
}
$p->save();
}