Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. function add_children( $post_id ) {
  2.  
  3.                 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  4.                     return;
  5.  
  6.                 if ( !wp_is_post_revision( $post_id )
  7.                 && 'page' == get_post_type( $post_id )
  8.                 && 'auto-draft' != get_post_status( $post_id ) ) {
  9.                     $show = get_post( $post_id );
  10.                     if( 0 == $show->post_parent ){
  11.                         $children =& get_children(
  12.                             array(
  13.                                 'post_parent' => $post_id,
  14.                                 'post_type' => 'page'
  15.                             )
  16.                         );
  17.  
  18.                          if( empty( $children ) ){
  19.  
  20.                 $child = array(
  21.                                 'post_type' => 'page',
  22.                                 'post_title'     => 'Title',
  23.                                 'post_name'      => 'page-title',
  24.                                 'post_date' => '2015-10-21 15:15:15',//[ Y-m-d H:i:s ]
  25.                                 'post_date_gmt' => '2015-10-21 15:15:15',//[ Y-m-d H:i:s ]
  26.                                 'post_content' => '',
  27.                                 'post_status' => 'publish',
  28.                                 'comment_status' => 'closed',
  29.                                 'post_parent' => $post_id,
  30.                                 'post_author' => 1,
  31.                             );
  32.                             $new_page_id = wp_insert_post( $child );
  33.                             update_post_meta( $new_page_id, '_wp_page_template', 'page-template.php' );
  34.  
  35.  
  36.                                 }
  37.  
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.             add_action( 'save_post', 'add_children' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement