プラグイン名 Search Regex
記事データの中身を一括検索、一括置換できるプラグインです。
インストール手順
プラグイン > 新規追加 > Search Regex > プラグインを検索 > いますぐインストール > プラグインを有効化
設定
ツール > Search Regex
例) サイト全体の記事内に書き込まれた「プラグイン」という文字列を検索し、それを「アプリ」に置き換えてみます。
SourceをPost content(本文)にし、Search patternに「プラグイン」と入力しSearchをクリックします。
29件ヒットしました。これをすべて「アプリ」に置き換えます。
Replaceをクリックすると置き換える前の確認ができます。
Replace & Saveをクリックして初めて置き換えられます。
29件すべてが一括で置き換えられました。
Source(検索・置換する文字列の場所)ここの選択を間違うとヒットしません。
- > Comment author
コメントの投稿者 - > Comment author email
コメント投稿者のメールアドレス - > Comment author URL
コメント投稿者の URL - > Comment content
コメント - > Post content
記事 - > Post excerpt
記事の抜粋 - > Post meta value
カスタムフィールド - > Post title
記事のタイトル - > Post URL
記事のURL - Limit to
検索と置換の上限数
> Nolimit
制限なし(すべて) - Order by 検索結果の表示順
> Ascending 昇順
> Descending 降順
※よくある「ヒットしない」
よくある「ヒットしない」は、Sourceを確認してください。CommentcontentとPostcontentでは全然違います。
あと、記事内の置き換えだけなら問題ないのですが、Post title(記事のタイトル)が、完全にヒットしない不具合があります。これを治すには下のファイルを編集します。
プラグイン > プラグイン編集 > Search Regex > 選択 > search-regex/searches/post_title.php
wp-content/plugins/search-regex/searches/post_title.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function find ($pattern, $limit, $offset, $orderby) { global $wpdb; $results = array (); $posts = $wpdb->get_results ($wpdb->prepare( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby LIMIT %d,%d", $offset,$limit ) ); if (count ($posts) > 0) { foreach ($posts AS $post) { if (($matches = $this->matches ($pattern, $post->post_title, $post->ID))) { foreach ($matches AS $match) $match->title = $post->post_title; $results = array_merge ($results, $matches); } } } return $results; } |
↑を↓に書き換えると記事タイトルもしっかりとヒットしてくれるようになります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
function find ($pattern, $limit, $offset, $orderby) { global $wpdb; $results = array (); $posts = $wpdb->get_results ($wpdb->prepare( "SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' ORDER BY ID $orderby" ) ); if ( $limit > 0 ) $sql .= $wpdb->prepare( " LIMIT %d,%d", $offset, $limit ); if (count ($posts) > 0) { foreach ($posts AS $post) { if (($matches = $this->matches ($pattern, $post->post_title, $post->ID))) { foreach ($matches AS $match) $match->title = $post->post_title; $results = array_merge ($results, $matches); } } } return $results; } |
コメントを残す