Is this possible to change editor screen immediately after someone picks some template from the drop down?
I need a metabox shown only when page template is page-portfolio.php
. I know I can use this code:
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
And than add my boxes using if
statements. The problem is it doesn’t work immediately. Is this even possible without very complex coding to do “catch” moment when user changes templates list without saving?
I know that the plugin Advanced Custom Field does that.
Checking its code, I saw that he deals with this issue using jQuery.
Using it as reference, I think this should work for you: