skip to Main Content

I would like to automatically generate some sequential WordPress posts that have numeric titles, for example "1", "2", "3"… etc.

I’m looking for an automatic system since I would like my posts to go from "1" to "999999".

No post content or meta is required, only the titles.

I’m aware of wp post generate but I have no idea on how to use it so that the post titles have the requirements explained above.

I’m working on a demo project so search engine optimization is not a concern at the moment.

CLI usage is accepted.

3

Answers


  1. You can achieve that quite simply by using a for loop with any arbitrary range (1-99 for example – or any other range you prefer)

    for i in {1..99}; do wp post create --post_title="This is post number $i" --post_status=publish; done
    

    This will call the wp post create command on each iteration of the loop and append the number to the post title.

    Login or Signup to reply.
  2. wordpress appends a numeric value automatically if there’s an existing post with the same post-title.

    so if the permalinks are set to be postname the URL will look as follow:

    my-post
    my-post-1
    my-post-2
    etc
    
    Login or Signup to reply.
  3. <?php
    
    // Create post object usinf for loop 
    for($i=1;$i<=9999;$i++){
    $my_post = array();
    $my_post['post_title']    = '<?php echo $i;?>';
    $my_post['post_content']  = 'This is my post-<?php echo $i;?>';
    $my_post['post_status']   = 'publish';
    $my_post['post_author']   = 1;
    $my_post['post_category'] = array(0);
    // Insert the post into the database
    wp_insert_post( $my_post );"
    }
    ?>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search