Mass Template change for children of a page

Tags:

Wordpress users, if you have created a site with a large number of pages ... and then decided to create a template that you would like to use for every page in a section of a site, you might find this useful.

Here is a bit of MySQL that changes the template of every child-page of the page with id=4:

update wp_postmeta set meta_value = "station.php"
  where meta_key="_wp_page_template" and 
        post_id in (select id from wp_posts where post_parent=4);

We use a sub-select to determine all the pages we want to change, and then set all those child-pages to have the 'station.php' template. That value, of course, will change -- you probably want to copy it from a page whose template you have set through the regular administration interface.