Skip to content

Instantly share code, notes, and snippets.

@kbcarte
Created November 3, 2022 14:38
Show Gist options
  • Save kbcarte/541d659751fed4a88c4cdf7b1bbbcab8 to your computer and use it in GitHub Desktop.
Save kbcarte/541d659751fed4a88c4cdf7b1bbbcab8 to your computer and use it in GitHub Desktop.
Insert new location pages based on array of city names
<?php
// example of FL
$imports = array('Brooksville','Spring Hill','New Port Richey','Hudson','Port Richey','Holiday','Dade City','Zephyrhills','Wesley Chapel','San Antonio','Kathleen','Webster','Saint Petersburg','Clearwater','Clearwater Beach','Largo','Seminole','Pinellas Park','Palm Harbor','Tarpon Springs','Safety Harbor','Dunedin','Odessa','Lutz','Tampa','Land O Lakes','Thonotosassa','Plant City','Lakeland','Auburndale','Bartow','Eagle Lake','Mulberry','Winter Haven','Brandon','Dover','Gibsonton','Lithia','Riverview','Ruskin','Apollo Beach','Sun City Center','Seffner','Valrico','Wimauma','Palmetto');
foreach( $imports as $i ){
$page_id = wp_insert_post(
array(
'comment_status' => 'close',
'ping_status' => 'close',
'post_title' => $i,
'post_name' => strtolower(str_replace(' ', '-', trim($i))),
'post_status' => 'publish',
'post_content' => '',
'post_type' => 'location',
'post_parent' => '7083' // id of the parent state page, FL in this case
)
);
}
echo "<h1>All done!</h1>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment