Advertisement
nomadone

generate wordpress pages on theme activation

Jan 23rd, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2.  
  3. // the intention with this script is to facilitate auto page generation when a new multisite instance is
  4. // created and the theme is activated
  5.  
  6. function recreate_page($post_data, $meta_data, $page_num=0) {
  7.   global $niche_settings_setting;
  8.  
  9.   // Delete the post if it already exists
  10.   if (($page = get_page_by_title($post_data['post_title']))) {
  11.     wp_delete_post($page->ID, true);
  12.   }
  13.  
  14.   // Insert the post into the database and set post meta data
  15.   $id = wp_insert_post($post_data);
  16.   if ($id) {
  17.     foreach ($meta_data as $meta_key=>$meta_value) {
  18.       update_post_meta($id, $meta_key, $meta_value);
  19.     }
  20.   }
  21. }
  22.  
  23. //////////////////////////////////// Create post object
  24.   $my_post = array(
  25.      'post_title' => 'Teacher',
  26.      'post_content' => '<h2>Teacher Page Content</h2>',
  27.      'post_status' => 'publish',
  28.      'post_type' => 'page',
  29.      'page_template' => 'teacher.php'
  30.   );
  31.  
  32. // Post meta data
  33.   $my_post_meta = array(
  34.     'custom_page_title'=>'Do You Have Back pain?',
  35.     'enable_conditions'=>'on',
  36.     'display_optin'=>'on',
  37.     '_genesis_layout'=>'full-width-content'
  38.   );
  39.   recreate_page($my_post, $my_post_meta, 1);
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement