Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccurtin/8e2b98e9ba4d57e3ae30b3c123501cd0 to your computer and use it in GitHub Desktop.
Save ccurtin/8e2b98e9ba4d57e3ae30b3c123501cd0 to your computer and use it in GitHub Desktop.
COPYING OVER WOOCOMMERCE PRODUCT CATEGORY IMAGES FROM A SOURCE TO TARGET SERVER

COPYING OVER WOOCOMMERCE PRODUCT CATEGORY IMAGES FROM A SOURCE TO TARGET SERVER

  • wp_posts

  • wp_postmeta

  • wp_termmeta

    --- EXPORT the product cat image "post ids" (used for the rest of the import/)
    --- note: `meta_value` contains the wp_posts post IDs we will be using
    SELECT meta_value FROM wp_termmeta INNER JOIN wp_term_taxonomy ON wp_termmeta.term_id = wp_term_taxonomy.term_id WHERE wp_termmeta.meta_key LIKE 'thumbnail_id' AND wp_term_taxonomy.taxonomy LIKE 'product_cat';
    ----------
    --- EXPORT the wp_postmeta
    SELECT * FROM wp_posts WHERE id IN(...)
    SELECT * FROM wp_postmeta WHERE post_id IN(...)
  • delete the returned post_ids in TARGET server (make sure they aren't critical posts):

    •     DELETE FROM wp_posts WHERE id IN(...);
          DELETE FROM wp_postmeta WHERE id IN(...);
  • export all wp_posts, wp_postmeta, and wp_termmeta from the SOURCE server and then import into TARGET

    • decide which columns to INSERT from wp_termmeta: meta_id, term_id, meta_key, meta_value, term_taxonomy_id, term_id, taxonomy, description, parent, count

    •     INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (...)
          ---
          INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES (...)
          ---
          INSERT INTO `wp_termmeta` (`meta_id`, `term_id`, `meta_key`, `meta_value`) VALUES (...)
  • copy over the actual image files(this is only for same server environments):

    •     rsync --ignore-existing --recursive /home/$SOURCE/public_html/wp-content/$MEDIA_GALLERY_FOLDER/ /home/$TARGET/public_html/wp-content/$MEDIA_GALLERY_FOLDER/ && find /home/$TARGET/public_html/wp-content/$MEDIA_GALLERY_FOLDER/ -mindepth 1 -maxdepth 1 -mtime -1 -exec chown $USER:$USER {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment