Jump to content

How do I edit multiple pages at once, based on a WHERE criteria?


desbest
 Share

Recommended Posts

<?php
	$a = $pages->find("template=yourtemplatename, fieldname=search_criteria");
	foreach ($a as $b) {
		$b->title = "New Name Here";
		$b->save('fieldname);
	}
?>

Its untested, but this should do the trick (for updating a title). However, someone please chime in if I have missed something.

 

Edited by louisstephens
updated to reflect kongondo's response
  • Like 1
Link to comment
Share on other sites

6 minutes ago, louisstephens said:

if I have missed something.

This:

$a = $pages->find("template=yourtemplatename, field=fieldname");

should be matching a value for the field...not the field name itself...:)

$a = $pages->find("template=yourtemplatename, fieldname=search_criteria");

If only saving the one field, it is more efficient to do:

$b->save('fieldname');

 

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

3 minutes ago, kongondo said:

This:


$a = $pages->find("template=yourtemplatename, field=fieldname");

should be matching a value for the field...not the field name itself...:)


$a = $pages->find("template=yourtemplatename, fieldname=search_criteria");

If only saving the one field, it is more efficient to do:


$b->save('fieldname');

 

Thanks  @kongondo, I have updated my response to reflect your revision. I knew I missed something.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...