[WordPress General] MySQLで一括置換する
いつのまにか半角ハイフン(-)が `–` に自動変換されていました。
[markdown]
WordPressとあわせてプラグインのバージョンアップもしたので、そのあたりの影響かもしれません。
## エントリー内で文字の自動変換が起きないようにする
よく知られている機能のようで、一般的にはこのような対処をするようです。
> * [[WordPress] WordPress:記事中にあるハイフンの自動変換を止める | Smart -Web Magazine](http://rfs.jp/sb/business/lab/201108081542.html)
“`php:/wp-content/themes/***/functions.php
remove_filter(‘the_title’, ‘wptexturize’); // 記事タイトル
remove_filter(‘the_content’, ‘wptexturize’); // 本文
remove_filter(‘comment_text’, ‘wptexturize’); // コメント欄
remove_filter(‘the_excerpt’, ‘wptexturize’); // 抜粋
“`
記事タイトルと本文に適用したのですが、うまく動いていないような気がするのと wptexturize がよく分からなかったので、他の文字に置き換えることにしました。
## 置き換わってしまった文字をMySQLで置換する
> * [[WordPress] 特定の文字を置換する方法 | 茶風荘](http://kickoo.net/wp/20120917024422.html)
エントリーのタイトルは、wp_posts の post_title にあたるようです。
“`php
UPDATE
wp_posts
SET
post_title = replace (post_title, ‘ –’, ‘:’)
“`
“`
$ mysql -u wp_blog -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
# 省略
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use wp_blog
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> UPDATE
-> wp_posts
-> SET
-> post_title = replace (post_title, ‘ –’, ‘:’);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1112 Changed: 0 Warnings: 0
mysql> UPDATE
-> wp_posts
-> SET
-> post_title = replace (post_title, ‘ -‘, ‘:’);
Query OK, 465 rows affected (0.03 sec)
Rows matched: 1112 Changed: 465 Warnings: 0
mysql> UPDATE
-> wp_posts
-> SET
-> post_title = replace (post_title, ‘ –’, ‘:’);
Query OK, 120 rows affected (0.00 sec)
Rows matched: 1113 Changed: 120 Warnings: 0
mysql>
“`
なんだかコピペに失敗してますが、コロン(:)に置き換えられました。
[/markdown]