Advertisement
arie_cristianD

create many dummy post

Nov 24th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. add_action( 'jnews_single_post_after_content', 'add_post' );
  2. function add_post() {
  3.     global $wpdb;
  4.     $post_count = 100000;
  5.     $chunk_size = 10000; // Adjust the chunk size as needed
  6.  
  7.     for ( $i = 0; $i < $post_count; $i += $chunk_size ) {
  8.         $posts = array();
  9.  
  10.         for ( $j = 0; $j < $chunk_size; $j++ ) {
  11.             // $post = array(
  12.             // 'post_title'   => 'Dummy Post ' . ( $i + $j ),
  13.             // 'post_content' => 'This is dummy content for post ' . ( $i + $j ),
  14.             // 'post_status'  => 'publish',
  15.             // 'post_author'  => 1, // Adjust the author ID as needed
  16.             // 'post_type'    => 'post',
  17.             // );
  18.             $postname = 'dummy-post-name-dummy-dummy' . ( $i + $j );
  19.  
  20.             $posts[] = '(\'Dummy Post ' . ( $i + $j ) . '\',\'This is dummy content for post ' . ( $i + $j ) . '\',\'publish\',' . 1 . ',\'post\',\'' . current_time( 'mysql' ) . '\',\'' . $postname . '\')';
  21.         }
  22.  
  23.         $query = "INSERT INTO {$wpdb->posts} (post_title, post_content, post_status, post_author, post_type ,post_date ,post_name) VALUES " . implode( ',', $posts );
  24.         $wpdb->query( $query );
  25.         // error_log( $query );
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement