Home / Admin / MFP > Deploy Show & Get Data
Duplicate Snippet

Embed Snippet on Your Site

MFP > Deploy Show & Get Data

Code Preview
php
<?php
add_action('acf/save_post', 'add_show_children');
function add_show_children($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
    if (!wp_is_post_revision($post_id)
        && 'show' == get_post_type($post_id)
        && 'auto-draft' != get_post_status($post_id)
        && 'draft' == get_post_status($post_id)
    ) {
        if (0 == get_post($post_id)->post_parent) {
            $countInt = (int) 1;
            $count = (string) $countInt;
            // & forces the value not the key
            $arr = array(
                'post_parent' => $post_id,
                'post_type' => 'show'
            );
            $children = get_children($arr);
            if (empty($children)) {
                $parent = array(
                    'ID' => $post_id,
                    'post_title' => get_city($post_id) . ' ' . get_year($post_id),
                    'post_name' => sanitize_title(get_city($post_id) . '-' . get_year($post_id)),
                    'menu_order' => $count . '9999'
                );
                $post_id = wp_update_post($parent);
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Visitor',
                    'post_name' => 'visitor',
                    'menu_order' => $count . '9900',
                    'post_content' => '',
                    'post_status' => 'publish',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Exhibitors',
                    'post_name' => 'exhibitors',
                    'menu_order' => $count . '9700',
                    'post_content' => '[exhibitor-page]',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Media',
                    'post_name' => 'media',
                    'menu_order' => $count . '9600',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Public',
                    'post_name' => 'public',
                    'menu_order' => $count . '9500',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'FAQ',
                    'post_name' => 'faq',
                    'menu_order' => $count . '9300',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Programming',
                    'post_name' => 'programming',
                    'menu_order' => $count . '9200',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Sponsors',
                    'post_name' => 'sponsors',
                    'menu_order' => $count . '9100',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Partner',
                    'post_name' => 'partner',
                    'menu_order' => $count . '9050',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Events',
                    'post_name' => 'events',
                    'menu_order' => $count . '9000',
                    'post_content' => '',
                    'post_status' => 'draft',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'Web', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Proposal',
                    'post_name' => 'proposal',
                    'menu_order' => $count . '6000',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Booth Select Info',
                    'post_name' => 'booth-select-info',
                    'menu_order' => $count . '5000',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Electronic Signature',
                    'post_name' => 'electronic-signature',
                    'menu_order' => $count . '4500',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Deposit',
                    'post_name' => 'deposit',
                    'menu_order' => $count . '4250',
                    'post_content' => '[payment-form type="deposit"]',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Finance',
                    'post_name' => 'finance',
                    'menu_order' => $count . '4000',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Show Information',
                    'post_name' => 'show-information',
                    'menu_order' => $count . '3900',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Curatorial',
                    'post_name' => 'curatorial',
                    'menu_order' => $count . '3800',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Regulations',
                    'post_name' => 'regulations',
                    'menu_order' => $count . '3700',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Shipping',
                    'post_name' => 'shipping',
                    'menu_order' => $count . '3600',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Booth',
                    'post_name' => 'booth',
                    'menu_order' => $count . '3500',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Onsite',
                    'post_name' => 'onsite',
                    'menu_order' => $count . '3400',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Ticketing',
                    'post_name' => 'ticketing',
                    'menu_order' => $count . '3300',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                $new_post = array(
                    'post_type' => 'show',
                    'post_title' => 'Concierge',
                    'post_name' => 'concierge',
                    'menu_order' => $count . '3200',
                    'post_content' => '',
                    'post_status' => 'private',
                    'post_parent' => $post_id,
                    'post_author' => 1,
                    'page_template' => 'template-show.php'
                );
                $new_post_id = wp_insert_post($new_post);
                wp_set_object_terms($new_post_id, 'ERC', 'area');
                wp_redirect(admin_url('edit.php?post_type=show&page=nestedpages-show'));
                exit;
            }
        }
    }
}

Comments

Add a Comment