Advertisement
kobial8

Metabox in Page Template

Mar 10th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. Step 01: Set pages as 'page' like follows:
  2. 'pages'       => array( 'page' ),
  3. Step 02: While declare the metabox function, use this code:
  4.   $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
  5.   $template_file = get_post_meta($post_id, '_wp_page_template',TRUE);
  6.   if ($template_file == 'pricing.php') {
  7.     ot_register_meta_box( $pricing_page_meta_box );
  8.   }
  9.  
  10. //here pricing.php is the Template Page file.
  11.  
  12. Your Code should Look like this:
  13.     $pricing_page_meta_box = array(
  14.     'id'          => 'pricing_page_meta_box',
  15.     'title'       => __( 'Our Service Custom Fields', 'theme-text-domain' ),
  16.     'desc'        => '',
  17.     'pages'       => array( 'page' ),
  18.     'context'     => 'normal',
  19.     'priority'    => 'high',
  20.     'fields'      => array(
  21.       array(
  22.         'label'       => __( 'Page Title', 'theme-text-domain' ),
  23.         'id'          => 'pricing_title',
  24.         'type'        => 'text',
  25.         'desc'        => __( 'Set Your Page Title Here', 'theme-text-domain' )
  26.  
  27.      ),
  28.       array(
  29.         'label'       => __( 'Page Sub Title', 'theme-text-domain' ),
  30.         'id'          => 'pricing_sub_title',
  31.         'type'        => 'text',
  32.         'desc'        => __( 'Set Your Page Sub Title Here', 'theme-text-domain' )
  33.  
  34.      ),
  35.       array(
  36.         'label'       => __( 'Services Included Title', 'theme-text-domain' ),
  37.         'id'          => 'include_title',
  38.         'type'        => 'text',
  39.         'desc'        => __( 'Set Your services inlcuded Title Here', 'theme-text-domain' )
  40.  
  41.      ),
  42.       array(
  43.         'label'       => __( 'Services Included Sub Title', 'theme-text-domain' ),
  44.         'id'          => 'include_sub_title',
  45.         'type'        => 'text',
  46.         'desc'        => __( 'Set Your services inlcuded Sub Title Here', 'theme-text-domain' )
  47.  
  48.      )
  49.    )
  50.   );
  51.  
  52.   /**
  53.    * Register our meta boxes using the
  54.    * ot_register_meta_box() function.
  55.    */
  56.   $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
  57.   $template_file = get_post_meta($post_id, '_wp_page_template',TRUE);
  58.   if ($template_file == 'pricing.php') {
  59.     ot_register_meta_box( $pricing_page_meta_box );
  60.   }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement