Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function born_to_be_page() {
- if(get_page_by_title('Page Title') == NULL ) {
- parent_page('Page Title');
- }
- if(get_page_by_title('Page Child') == NULL ) {
- child_page('Page Child');
- }
- }
- add_action('init','born_to_be_page');
- function parent_page($pageName) {
- $createParentPage = array(
- 'post_title' => $pageName,
- 'post_content' => 'Some Content',
- 'post_status' => 'publish',
- 'post_type' => 'page',
- 'post_name' => sanitize_title($pageName)
- );
- // Insert the post into the database
- $parentPage = wp_insert_post($createParentPage);
- wp_update_nav_menu_item(get_term_by('slug', 'primary', 'nav_menu' )->term_id, 0, [
- 'menu-item-object-id' => $parentPage,
- 'menu-item-type' => 'post_type',
- 'menu-item-object' => 'page',
- 'menu-item-status' => 'publish'
- ]);
- }
- function child_page($pageName) {
- $createChildPage = array(
- 'post_title' => $pageName,
- 'post_content' => 'Some Content',
- 'post_status' => 'publish',
- 'post_author' => 1,
- 'post_type' => 'page',
- 'post_parent' => 158,
- 'post_name' => sanitize_title($pageName)
- );
- // Insert the post into the database
- wp_insert_post($createChildPage);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement