admin管理员组文章数量:1332873
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
本文标签: phpAutomatically create child pages and grandchild pages when saving a (parent) page
版权声明:本文标题:php - Automatically create child pages and grandchild pages when saving a (parent) page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742296084a2448753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论