Jump to content

Recalculate name (url) from API somehow?


joe_g
 Share

Recommended Posts

foreach ($pages->find('template=basic-page, limit=50') as $p) {
	$p->of(false);
	$p->title = "My New Title";// if using a new title...otherwise comment out this line 
	$p->name = $sanitizer->pagenName($p->title);
	$p->save();
	$p->of(true);
}

If renaming in the thousands let us know so that we can adjust the code...

  • Like 5
Link to comment
Share on other sites

Just to add to @kongondo's code, if your site is not in English, you may want to consider:

$p->name = $sanitizer->pageName($p->title, true);

You can read more about that sanitizer option here: https://processwire.com/api/ref/sanitizer/page-name/

or:

$p->name = $sanitizer->pageNameUTF8($p->title);

https://processwire.com/api/ref/sanitizer/page-name-utf8/

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...