How to dynamically save a selected option from page “Templates” selectbox?

When I select a template for a page from the “Templates” selectbox, the selected item gets “value=selected” only after I hit save draft/publish/update.

<option value='template-gallery.php' selected='selected'>Gallery</option>

Read More

How can the option receive the value “selected” without the need of save/publish/update hit button? (like on widgets page: they get saved without page refresh)

Thank you!

Related posts

Leave a Reply

1 comment

  1. This would have to be fully coded and tested, but I think the roadmap is:

    Deregister the Default Meta Box and Make a Custom One

    @MikeSchinkel answer to this question is very detailed and thoughtful: Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?

    In that case, it is for duplicating the Pages Template Meta Box into Posts.

    This other Q&A ( How To Change Custom Taxonomy To Radio Buttons ) provides an example of replacing the Taxonomies Meta Box.

    Add Ajax to the Custom Templates Meta Box

    In this answer, there’s an example of custom meta box that runs an Ajax call, that in turn makes a database query to modify an attachment parent.

    To do the Page Template live switch, it would be a matter of modifying the table wp_postmeta where the current template value is stored.

    The meta_key name is _wp_page_template and its value the template file name.

    results of query wp_postmeta _wp_page_template