skip to Main Content

Been googling, testing and searching for hours to no avail…I’m hoping someone here can help me with what I presume is a fairly simple SQL command, but I’m very basic about it and just getting errors.

My situation is as follows:
I need to take certain row data from wp_postmeta table and stuff it into certain row data into wp_posts. I’m migrating some 50,000 orders from drupal to wordpress, but due to weirdness, order #’s don’t match up.

What I am looking to do is copy the meta_value in the wp_postmeta table, but only where meta_key LIKE "_fgd2wp_old_uc_order_id"

Then take this specific query and dump it into wp_posts table, into the ID column, but only where post_type LIKE shop_order.

I can find the data I want through the below search queries…but unsure how to copy. Tried and failed. Any help would be greatly appreciated. Thanks!

SELECT meta_value FROM wp_postmeta WHERE meta_key LIKE ‘%old_uc_order_id%’
SELECT ID FROM wp_posts WHERE post_type LIKE ‘shop_order’

Tried this command…but it errors saying WHERE isn’t expected. Not sure how to specify what i need?

INSERT INTO wp_posts (ID)
WHERE post_type = ‘shop_order’
SELECT
meta_value
WHERE meta_key = ‘_fgd2wp_old_uc_order_id’
FROM wp_postmeta;

2

Answers


  1. try this
    INSERT INTO target_table (column1, column2)
    SELECT
    column1,
    column2
    FROM source_table

    Login or Signup to reply.
  2. To achieve the desired migration of data from the wp_postmeta table to the wp_posts table, you can use the following SQL query:INSERT INTO wp_posts (ID) SELECT meta_value FROM wp_postmeta WHERE meta_key LIKE '_fgd2wp_old_uc_order_id' AND EXISTS ( SELECT 1 FROM wp_posts WHERE post_type LIKE 'shop_order' AND ID = wp_postmeta.post_id );

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search