Skip to content

Instantly share code, notes, and snippets.

@mgratch
Created August 3, 2018 16:45
Show Gist options
  • Save mgratch/a1f4117e92abfca0bb54dae39279e42b to your computer and use it in GitHub Desktop.
Save mgratch/a1f4117e92abfca0bb54dae39279e42b to your computer and use it in GitHub Desktop.
Bring current broken live data local and fix it run locally and enter appropriate ssh information for the live site. Make sure live is running at least wp-cli version X.X
// Bring current broken live data local and fix it
// run locally and enter appropriate ssh information for the live site.
// make sure live is running at least wp-cli version X.X
rm _live_posts_export.xml; // make sure we are starting clean
// pull the live sites posts and export them into a local xml file
wp export --post_type=post --with_attachments --stdout --ssh=vagrant@localhost/srv/www/wordpress-default/public_html > _live_posts_export.xml;
// delete all the posts off the local site (we could delete only based on guid if necessary?)
wp post delete $(wp post list --post_type='post' --post-status=all --format=ids) --force;
// make sure the wordpress-importer plugin is installed locally
wp plugin install wordpress-importer --activate;
// import the live sites posts
wp import _live_posts_export.xml --authors=create;
// loop through all the post ids and convert `awesome_intro`s to post_excerpt
for id in $(wp post list --post_type=post --format=ids);
do wp post update $id --post_excerpt=$(wp post meta get $id awesome_intro);
wp post meta delete $id awesome_intro;
done;
// clean up after ourselves
rm _live_posts_export.xml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment