Jump to content

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


Recommended Posts

Posted

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

So if all the fields in the pages match a certain criteria, how do I update them all at once?

I have searched the forum for help and can't find anything.

Posted (edited)
<?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
Posted (edited)
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
Posted
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.

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
  • Recently Browsing   0 members

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