wp_insert_post to dynamically generate child pages for a given page using a predefined array of values. The goal is to give each child page the same slug.
For example, clicking "Generate Pages" on "example-page" loops through
wp_insert_post and creates two child pages:
The trouble is that WordPress is adding numbers after the slug on the child pages (because similar child pages have already been created for a different page).
My guess is that it's doing a check on slug availability irrespective of the parent/child relationship.
I've experimented with trying to run
wp_update_post after the insertion but to no avail.
Here's a code sample:
$new_page = array( 'post_title' => $child_page["title"], 'post_parent' => $parent_id, 'post_name' => $child_page["slug"], 'post_content' => $child_page["content"], 'post_status' => 'publish', 'post_type' => 'territory' ); $new_page_id = wp_insert_post($new_page);
Explanation: I am looping through an array of
$child_pages, in which I've set the unique values for title, slug, and content.