• 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 2 years, 3 months ago by digitalforge.
    • This topic was modified 2 years, 3 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.www.ads-software.com/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.www.ads-software.com/reference/functions/wp_insert_post/

    And there’s a REST API as well. Here’s an example: 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 2 years, 3 months ago by George Appiah.
    Thread Starter digitalforge

    (@digitalforge)

    Looks good, thank you so much for your reply @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 2 years, 3 months ago by digitalforge.

    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.