Created
April 16, 2015 20:39
-
-
Save kosmiq/33ccc6a38fe5644de299 to your computer and use it in GitHub Desktop.
WordPress: Display custom Meta box on specific page template only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*awesome tip from http://www.paulund.co.uk/display-post-meta-box-specific-page-templates*/ | |
add_action('add_meta_boxes', 'add_product_meta'); | |
function add_product_meta() | |
{ | |
global $post; | |
if(!empty($post)) | |
{ | |
$pageTemplate = get_post_meta($post->ID, '_wp_page_template', true); | |
if($pageTemplate == 'page-templates/product-page.php' ) | |
{ | |
add_meta_box( | |
'product_meta', // $id | |
'Product Information', // $title | |
'display_product_information', // $callback | |
'page', // $page | |
'normal', // $context | |
'high'); // $priority | |
} | |
} | |
} | |
function display_product_information() | |
{ | |
// Add the HTML for the post meta | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Kosmiq,
Great job!
I just can not save these fields.
I'm trying to use something like:
function save_meta_page( $post_id ) {
$pageTemplate = get_post_meta($post_id, '_wp_page_template', true);
}
add_action('save_post', 'save_meta_page', 9999, 1);
How do I save these fields to the specific template?