Skip to content

Instantly share code, notes, and snippets.

@aprea
Created March 21, 2014 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprea/9678766 to your computer and use it in GitHub Desktop.
Save aprea/9678766 to your computer and use it in GitHub Desktop.
Generate dummy WordPress posts
<?php
// Generates a SQL dump that imports a number of posts into the wp_posts table
set_time_limit(0);
$table_prefix = 'wp_';
$max_posts = 50000;
$max_inserts_per_query = 50;
$file = dirname( __FILE__ ) . '/dump.sql';
$fh = fopen( $file , 'w' ) or die( 'can\'t open file: ' . $file );
$paragraphs = array(
'Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.',
'Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.',
'A small river named Duden flows by their place and supplies it with the necessary regelialia.',
'It is a paradisematic country, in which roasted parts of sentences fly into your mouth.',
'Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.',
'The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen.',
'She packed her seven versalia, put her initial into the belt and made herself on the way.'
);
$insert_template = sprintf( "INSERT INTO `%sposts` ( `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES\n", $table_prefix );
$post_count = 0;
while ( $post_count < $max_posts ) {
$new_posts = array();
while ( $post_count < $max_posts && count( $new_posts ) < $max_inserts_per_query ) {
$date = gmdate( 'Y-m-d H:i:s' );
$title = sprintf( 'Post %s', $post_count );
$slug = str_replace( ' ', '-', strtolower( $title ) );
$guid = sprintf( 'http://example.com/%s', $slug );
$content = (array) array_rand( $paragraphs, mt_rand( 1, ( count( $paragraphs ) - 1 ) ) );
$content = array_values( array_intersect_key( $paragraphs, array_flip( $content ) ) );
shuffle( $content );
$content = '<p>' . implode( '</p><p>', $content ) . '</p>';
$new_posts[] = sprintf( "(NULL, 1, '%s', '%s', '%s', '%s', '', 'publish', 'open', 'open', '', '%s', '', '', '%s', '%s', '', 0, '%s', 0, 'post', '', 1)", $date, $date, $content, $title, $slug, $date, $date, $guid );
++$post_count;
}
$insert = $insert_template;
$insert .= implode( ",\n", $new_posts );
$insert .= ";\n";
fwrite( $fh, $insert );
}
fclose($fh);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment