Advertisement
geminilabs

Export reviews as WooCommerce reviews (WordPress comments)

Oct 28th, 2021 (edited)
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.39 KB | None | 0 0
  1. -- MySQL Query to select all reviews that are assigned to a product and with review content
  2. -- which can be used to export as a CSV and imported to the wp_comments table as WooCommerce reviews.
  3.  
  4. -- 1. Install the [Database Browser](https://wordpress.org/plugins/database-browser/) plugin
  5. -- 2. Go to the "Tools > Database Browser" page
  6. -- 3. Click the "Select table" button (it doesn’t matter which table is selected)
  7. -- 4. Copy the table prefix of your tables (for example, if the table is `wp_posts`, the prefix is the first part with the underscore `wp_`).
  8. -- 4. Click the "Edit query" button
  9. -- 5. Paste the SQL query, replacing every instance of `wp_` in the SQL query with your table prefix.
  10. -- 6. Click the "Run query" button
  11. -- 7. Click the "CSV" button to download the results
  12.  
  13. SELECT
  14.     ap.post_id as comment_post_ID,
  15.     r.name as comment_author,
  16.     r.email as comment_author_email,
  17.     r.ip_address as comment_author_IP,
  18.     p.post_date as comment_date,
  19.     p.post_date_gmt as comment_date_gmt,
  20.     p.post_content as comment_content,
  21.     r.is_approved as comment_approved,
  22.     'review' comment_type,
  23.     p.post_author as user_id
  24. FROM wp_glsr_ratings AS r
  25. INNER JOIN wp_posts AS p ON r.review_id = p.ID
  26. INNER JOIN wp_glsr_assigned_posts AS ap ON r.ID = ap.rating_id
  27. INNER JOIN wp_posts AS p2 ON ap.post_id = p2.ID
  28. WHERE p.post_content IS NOT NULL
  29. AND p2.post_type = 'product'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement