desbest Posted October 20, 2017 Posted October 20, 2017 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.
louisstephens Posted October 20, 2017 Posted October 20, 2017 (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 October 20, 2017 by louisstephens updated to reflect kongondo's response 1
kongondo Posted October 20, 2017 Posted October 20, 2017 (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 October 20, 2017 by kongondo 1
louisstephens Posted October 20, 2017 Posted October 20, 2017 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now