Update page path programmatically

Submitted by remo - 3 years ago

A page has to be found somewhere and sometimes you might want to change that path, a part of the URL from within your code.

// get a page object, hard coded the page ID 131, replace with something you actually work with
$c = Page::getByID(131);

// specify the new path
$data = array(
    'cHandle' => 'new-path'
);

// update collection
$c->update($data);

// make sure the path table for the current page as well as its children are updated too.
// if you specify "true", concrete5 will retain the old path
$c->rescanCollectionPath(true);
Stats Categories Tags
comments powered by Disqus