Wordpress - Import and replace existing page/post content

One option might be to export both XML files, merge them using a file merging tool like http://winmerge.org, delete all posts and replace with the merged version.


Run A Query to Delete All Staging Posts before Importing From Dev

Because menus and pages are custom post types, this will update all posts, pages, and menus to match your dev site.

  1. Delete all posts in the staging server by running a database query. Note that the code requires setting a userid. modify it if there are more users or run it more than once.

    SET @WPUSERID='1';
    -- end config
    -- Delete a,b,c 
       FROM wp_posts a 
       LEFT JOIN wp_term_relationships b 
       ON (a.ID = b.object_id)
       LEFT JOIN wp_postmeta c 
       ON (a.ID = c.post_id) 
       WHERE a.post_author = @WPUSERID;
    
  2. Import the XML file that you exported from the Dev site.

Caution: Back up your databases for both dev and staging in case you accidently get them mixed up (you think you're connected to stage for example, and you are really connected to dev when you do the delete) .

Be safe: view posts before deleting

Select * FROM wp_posts a 
LEFT JOIN wp_term_relationships b 
ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c 
ON (a.ID = c.post_id) 
WHERE a.post_author = @WPUSERID;