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
- About
- Visitor Info
-
- One grandchild page (child of VISITOR INFO)
-
- Two grandchild page (child of VISITOR INFO)
-
- Three grandchild page (child of VISITOR INFO)
- Exhibitors
- Sponsors
- Press
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296085a4417146.html
评论列表(0条)