Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_children( $post_id ) {
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- if ( !wp_is_post_revision( $post_id )
- && 'page' == get_post_type( $post_id )
- && 'auto-draft' != get_post_status( $post_id ) ) {
- $show = get_post( $post_id );
- if( 0 == $show->post_parent ){
- $children =& get_children(
- array(
- 'post_parent' => $post_id,
- 'post_type' => 'page'
- )
- );
- if( empty( $children ) ){
- $child = array(
- 'post_type' => 'page',
- 'post_title' => 'Title',
- 'post_name' => 'page-title',
- 'post_date' => '2015-10-21 15:15:15',//[ Y-m-d H:i:s ]
- 'post_date_gmt' => '2015-10-21 15:15:15',//[ Y-m-d H:i:s ]
- 'post_content' => '',
- 'post_status' => 'publish',
- 'comment_status' => 'closed',
- 'post_parent' => $post_id,
- 'post_author' => 1,
- );
- $new_page_id = wp_insert_post( $child );
- update_post_meta( $new_page_id, '_wp_page_template', 'page-template.php' );
- }
- }
- }
- }
- }
- add_action( 'save_post', 'add_children' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement