Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 3, 2018 12:03
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 pandanote-info/50627eb20130b809872a3eeb2e589ac8 to your computer and use it in GitHub Desktop.
Save pandanote-info/50627eb20130b809872a3eeb2e589ac8 to your computer and use it in GitHub Desktop.
Wordpressで画像のサムネイルを後付けで設定するために実際に実行したSQL文。なお、動作についてはいっさい保証できません。
MariaDB [hoge]> update wp_posts set post_content=regexp_replace(
regexp_replace(post_content,
'(<img src=.*wp-image-(\\d+)[^>]*>)',
'<a href="https://pandanote.info/?attachment_id=\\2" rel="attachment wp-att-\\2">\\1</a>'),
'(?:(<a href[^>]*>))+(<img[^>]*>)(</a>)+',
'\\1\\2\\3')
where post_status = 'publish' and post_type='post';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment