• He creado un custom post type llamado «películas»

    A través de una función que he incluido en functions.php he conseguido que al crear una nueva película (crear un nuevo post «peliculas») se cree de forma automática un post hijo (child page). Lo he conseguido a partir de este código:

    function wpa8582_add_show_children( $post_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    
    if ( !wp_is_post_revision( $post_id )
    && 'peliculas' == 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' => 'peliculas'
                )
            );
            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' );
    
    

    Lo que no sé, es cómo hacer que se cree un hijo dentro del hijo que se genera (es decir, un nieto del post padre o grandchild page) y que también se haga de forma automática.

    ¿Alguien me echa una mano?

    Necesitaría que se quedase una estructura así:

    1. PARENT PAGE: PELÍCULA
    1a. REPARTO
    1a-1. ACTOR1
    1a-2. ACTOR2
    1a-3. ACTOR3
    1b. TRAILER

Viendo 1 respuesta (de un total de 1)
Viendo 1 respuesta (de un total de 1)
  • El debate ‘Crear child pages y grandchild pages de forma automática al guardar un post’ está cerrado a nuevas respuestas.