Created
February 20, 2013 10:48
-
-
Save thisislawatts/4994707 to your computer and use it in GitHub Desktop.
Simple way for inserting a number of posts. Originally set up for 280+ records imported from a XML file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* WordPress Content Generation | |
* | |
*/ | |
/** | |
* Loads the WordPress Environment and Template | |
*/ | |
require('./wp-blog-header.php'); | |
/** | |
* Loop over a $posts array to generate a number of posts | |
*/ | |
function setup_posts() { | |
$author_id = 1; | |
$posts = array( | |
array( | |
"number" => 101, | |
"title" => "Unity House", | |
"text" => "Feasibility study for mixed-use development", | |
) | |
); | |
foreach ( $posts as $post ) { | |
$post_id = -1; | |
$slug = preg_replace( '/\s/', '-', strtolower($post['title']) ); | |
// Basic slugerisation, only works only whitespace. | |
$post_id = wp_insert_post( array( | |
'comment_status' => 'closed', | |
'ping_status' => 'closed', | |
'post_author' => $author_id, | |
'post_name' => $slug, | |
'post_title' => $post['title'], | |
'post_status' => 'publish', | |
'post_type' => 'project' | |
) ); | |
if (!$post_id) { | |
echo "Failed: {$post['title']}\n"; | |
} else { | |
echo "Setup : {$post['title']} - {$post_id}\n"; | |
} | |
} | |
} | |
setup_posts(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment