Jump to content

batch to update a field of a template


adrianmak
 Share

Recommended Posts

I added a new field of an existing template where this template has already hundreds of page had beed created.

I put following  code on home page temporary.


$result = $pages->find("template=mytemplate");

foreach ($result as $p) {
  $p->new_field = time();
  $p->save();
}

After refreshing the home page, all pages with this template should be updated.

I log-in to backend admin, and found that the field is still empty.

Link to comment
Share on other sites

That should work and works fine here. I am wondering if there is some issue with the "hundreds of pages"?  How many fields are there in the template?

One thing to try might be to:

$page->save("new_field");

since this only saves that one field, rather than all of them.

I don't think it is necessary in this case, but it is always good to do:

$p->of(false);

before saving.

Are there any errors being logged?

Link to comment
Share on other sites

That should work and works fine here. I am wondering if there is some issue with the "hundreds of pages"?  How many fields are there in the template?

One thing to try might be to:

$page->save("new_field");

since this only saves that one field, rather than all of them.

I don't think it is necessary in this case, but it is always good to do:

$p->of(false);

before saving.

Are there any errors being logged?

I should have $p->of(false); it

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...