php - Automatically create child pages and grandchild pages when saving a (parent) page

I have a bit of a tricky one...I have a hierarchical Custom Post Type ('shows') that represents events. Is it

I have a bit of a tricky one...

I have a hierarchical Custom Post Type ('shows') that represents events. Is it possible for the user to create a new page (ie show), save the page and for Wordpress to automatically create a defined set of child pages with defined names and grandchild pages (child of one of them)?

Here is something similar:

function wpa8582_add_show_children( $post_id ) {  
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    return;

  if ( !wp_is_post_revision( $post_id )
    && 'show' == 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' => 'show'
            )
        );
        if( empty( $children ) ){
            $child = array(
                'post_type' => 'show',
                'post_title' => 'About',
                'post_content' => '',
                'post_status' => 'draft',
                'post_parent' => $post_id,
                'post_author' => 1,
                'tax_input' => array( 'your_tax_name' => array( 'term' ) )
            );
            wp_insert_post( $child );
        }
    }
  }
}

add_action( 'save_post', 'wpa8582_add_show_children' );

And here is what I need:

//Save parent page London

//Children automatically created

/LONDON

  1. About
  2. Visitor Info
    • One grandchild page (child of VISITOR INFO)
    • Two grandchild page (child of VISITOR INFO)
    • Three grandchild page (child of VISITOR INFO)
  3. Exhibitors
  4. Sponsors
  5. Press

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296085a4417146.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信