Advertisement
baker85

custom field by template wordpress

Sep 28th, 2012
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. function mes_pages_meta_init(){
  2.     $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
  3.    
  4.     if(get_post_meta($post_id,'_wp_page_template',TRUE) == 'votre-template.php'){
  5.         add_post_meta($post_id, 'custom_field_1', 'valeur-par-defaut', true);
  6.         add_post_meta($post_id, 'custom_field_2', 'valeur-par-defaut', true);
  7.     }
  8.     elseif(get_post_meta($post_id,'_wp_page_template',TRUE) == 'votre-autre-template.php'){
  9.         add_post_meta($post_id, 'custom_field_3', 'valeur-par-defaut', true);
  10.         add_post_meta($post_id, 'custom_field_4', 'valeur-par-defaut', true);
  11.         add_post_meta($post_id, 'custom_field_5', '', true);
  12.     }
  13.    
  14.     return true;
  15. }
  16.  
  17. add_action('wp_insert_post', 'mes_pages_meta_init');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement