Title: How to programmatically (SQL) duplicate a post
Last modified: November 12, 2022

---

# How to programmatically (SQL) duplicate a post

 *  [digitalforge](https://wordpress.org/support/users/digitalforge/)
 * (@digitalforge)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/how-to-programmatically-sql-duplicate-a-post/)
 * I made a “POST” and I would like to programmatically (MySQL) duplicate it and
   only change the text in it.
 * Can anyone tell me if that is possible and if, how to do it? All I need to do
   is where to get the data from (what tables and what connections) and where to
   store it again.
 * What I would like to achieve is making ca. 1000 pages which are an exact 1:1 
   copy, with only a different text.
 * The only two tables I can find is wp_posts and wp_postmeta and those do not seem
   to include the text which in is the post.
    -  This topic was modified 3 years, 6 months ago by [digitalforge](https://wordpress.org/support/users/digitalforge/).
    -  This topic was modified 3 years, 6 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Everything else WordPress
      topic

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [George Appiah](https://wordpress.org/support/users/gappiah/)
 * (@gappiah)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/how-to-programmatically-sql-duplicate-a-post/#post-16190273)
 * > The only two tables I can find is wp_posts and wp_postmeta and those do not
   > seem to include the text which in is the post.
 * This should help: [https://codex.wordpress.org/Database_Description](https://codex.wordpress.org/Database_Description)
 * But note that these are other (arguably better) options besides making direct
   SQL calls.
 * There’s a WordPress-native PHP function for creating posts: [https://developer.wordpress.org/reference/functions/wp_insert_post/](https://developer.wordpress.org/reference/functions/wp_insert_post/)
 * And there’s a [REST API](https://developer.wordpress.org/rest-api/) as well. 
   Here’s an example: [https://rudrastyh.com/wordpress/rest-api-create-post.html](https://rudrastyh.com/wordpress/rest-api-create-post.html)
 * Finally, if you have your content in CSV or XML format, there are plugins (eg
   WP All Import) that can import these into WordPress very easily.
 * Of course, if this is a one-time job, direct SQL import might be the preferred
   approach.
    -  This reply was modified 3 years, 6 months ago by [George Appiah](https://wordpress.org/support/users/gappiah/).
 *  Thread Starter [digitalforge](https://wordpress.org/support/users/digitalforge/)
 * (@digitalforge)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/how-to-programmatically-sql-duplicate-a-post/#post-16190642)
 * Looks good, thank you so much for your reply [@gappiah](https://wordpress.org/support/users/gappiah/)!
   Just one question. How would I copy the “looks” of a previous post I made? I 
   want to duplicate that one and just replace the text of one single element.
 * Anyways, I will look into that API call and give it a try!
    -  This reply was modified 3 years, 6 months ago by [digitalforge](https://wordpress.org/support/users/digitalforge/).
 *  [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * (@mrtom414)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/how-to-programmatically-sql-duplicate-a-post/#post-16193030)
 * Maybe you should look at reusables blocks and block patterns. When you click 
   the + to add blocks you will see 2 other tabs. One for patterns and the other
   is reusable blocks.
 * Reusable blocks allow you to make a copy of a block or a group of blocks and 
   save them. If it a group of blocks you might want to add them to a group container.
   You can drag the blocks back into a post of your choice.
 * All reusable blocks are tied together. So if you update one all the blocks will
   change to the same content regardless of where they are used at. I know this 
   isn’t the effect you want. But, There also an option to remove the group from
   reusables block.
 * Try looking at some tutorials for reusable blocks. I think it pretty close to
   what you need.
 * Don’t try missing with the database files. To WordPress everything is a post 
   which includes post,pages,and custom post types. The post meta table just classifies
   what they are and where they are to be used. Also, WordPress changes the information
   when it moves from the front end to the backend. I wouldn’t try to manually change
   the database unless there is no other choice.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to programmatically (SQL) duplicate a post’ is closed to new replies.

## Tags

 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/how-to-programmatically-sql-duplicate-a-post/#post-16193030)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
