1

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
  • It seems like the code you've pasted there does most of what you're asking. Do you have a more specific question, like how to implement this code, or how to create many pages even though this code only creates 1? If you haven't already it might be worth trying to test this code in functions.php or in a plugin – mozboz Jul 2 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.