Skip to content
Advertisement

Bulk move 20000 post_meta value to wp_content with mysql command

I have more than 1 million WordPress article, I want to achieve the following effect through mysql:

copy the post_meta key value named views to wp_content field.

I know how to insert value from table wp_posts to table wp_postmeta, but how to move value from wp_postmeta to wp_posts? I used code like this:

update `wp_posts` p join
       `wp_postmeta` m
       on p.id = m.post_id
    set p.post_content = m.views 
    where p.post_status='publish' and m.views != '' limit 1;

but get error messge:

ERROR 1054 (42S22): Unknown column ‘m.views’ in ‘where clause’

how to fixed it ? thanks !

Advertisement

Answer

    update `wp_posts` p join
    `wp_postmeta` m
    on p.ID = m.post_id
    set p.post_content = m.meta_value
    where p.post_status='publish'
            AND m.meta_key = 'views' 
            AND m.meta_value != '';

this works well , but take a long time

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement