Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>

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!

share|improve this question
    
because on widgets page wordpress loads some javascript which handles the transfer via AJAX. –  Mridul Aggarwal Nov 24 '12 at 14:15
    
@MridulAggarwal I thought so...Im wondering if theres a jquery solution for this. Ive seen selectboxes which enables other things when options are selected but Im not sure if this can be made on wp admin selectboxes too. Thanks for your reply! –  Madalin Nov 24 '12 at 14:39

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
Thanks for your complete answer. I`ll give it a try and see if is really working! –  Madalin Nov 25 '12 at 9:57
    
Nice, and if you build a working code please publish as an answer here :) –  brasofilo Nov 25 '12 at 11:48
    
Will do! Thanks again! –  Madalin Nov 25 '12 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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