Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 3, 2018 12:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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