A component of a site I am building has changed and as a result I need to move the entries over to a new template. It looks like this template data is stored in exp_sites > site_pages.

How would you approach this? Not looking to manually update 300+ entries.


We also provide this script in the docs: http://buildwithstructure.com/documentation/how_can_i_batch_update_templates_for_existing_entries/


I suggest copy/pasting the serialized array from the site_pages column and using an online generator to unserialize it. Then copy the unserialized array over to a text editor to find/replace the old template_id with the new the template_id.

The array contains a URI array & Template array. The template array is the last array. So look for [1] => 4 which is [entry_id] => template_id

I would do a find and replace just for template_id: => 5 to => XX

As far as serializing the array, I haven't found a online generator to make it easy. You may just need to create a template and enable PHP to serialize it for you, then copy/paste it back into the site_pages column.

Always backup first!


I just found this script to batch update entries.

2nd Update

Added the two lines of code for the updating the old template id with the new. Should save a couple clicks

* Batch reset template_id for Structure entries

$str = base64_decode("PASTE-VALUE-FROM_site_pages_FIELD-HERE");
$arr = unserialize ($str);
$old_template_id = PASTE-OLD-TEMPLATE-ID-HERE; //e.g. 3;
$new_template_id = PASTE-NEW-TEPLATE-ID-HERE;//e.g. 24;

// Set new template_id
foreach( $arr[1]['templates'] as $key => $template_id )
   if ($template_id == $old_template_id)        
      $arr[1]['templates'][$key] = $new_template_id;

// Output
print '<pre>';
print '</pre>';

// Serialize & encode
$new_arr = serialize($arr);
$new_str = base64_encode($new_arr);

// Output for copy/paste
print "<textarea rows='100' cols='80'>";
print $new_str;
print "</textarea>";

  • I couldn't get this script to work, but the version Travis shared below did the trick. Thanks! – Dan Johnson Feb 7 '13 at 18:59
  • Yeah, that's the update script. I was unaware they had that in their docs. Glad you got it working. – Siebird Feb 7 '13 at 19:12
  • No offense intended in the downvote, but Travis' answer uses official documentation to provide a working solution. – Mark Drzycimski Feb 7 '13 at 19:22
  • It's the effort that counts. If I wanted to, I could add the two lines of code that it's missing to be correct, but I left as is. Plus Wedodan just needs to mark Travis's answer correct to supersede my answer. – Siebird Feb 7 '13 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.