脳内プラグイン

プログラム関連のメモ書きというか落書きというか

超絶便利なプラグイン「Search Regex Plugin」をカスタムポストタイプに適応する方法

Wordpressを公開前にテストディレクトリでつくって
そんでもってひと通り記事を投稿したあとで公開となったとき
画像のパスが変わっちゃって、あらららら〜ってなることありますよね?

そんな時に超絶便利な画像パスを一括で置換してくれる
Search Regex Plugin というものがあります。

使い方はこちらの記事を参考にさせていただきました。
http://nori510.com/archives/10803

で、デフォルトでは、カスタムポストタイプの項目が
ないので(当たり前か....)なんとなくノリで変更してみたら
なんとなくできたっぽいのでまぁそれをメモ。

とりあえず、plugins/search-regex/searches までいくと
コンテンツのファイルが並んでいるので、post_content.phpを複製して、
任意の名前をつける(ここではcustom_content.phpとしておく)

そんでもって、下記の箇所を変更していく

#3行目クラス名変更
変更前

class SearchPostContent extends Search

変更後

class SearchCustomContent extends Search

#10行目セレクト文変更 -> custom_postの部分はカスタム投稿タイプのid
変更前

$posts   = $wpdb->get_results ( "SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' AND post_type IN ('post','page') ORDER BY ID $orderby" );

変更後

$posts   = $wpdb->get_results ( "SELECT ID, post_content, post_title FROM {$wpdb->posts} WHERE post_status != 'inherit' AND post_type IN ('custom_post') ORDER BY ID $orderby" );

#36行目 オプションの部分のクラス名を変更
変更前

$options[] = '<a href="#" onclick="regex_replace (\'SearchPostContent\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';

変更後

$options[] = '<a href="#" onclick="regex_replace (\'SearchCustomContent\','.$result->id.','.$result->offset.','.$result->length.',\''.str_replace ("'", "\'", $result->replace_string).'\'); return false">replace</a>';

これで、カスタムポストタイプのポストコンテンツを選択できるようになるはずです。
上記の内容はあくまで個人的に試した結果のメモなので、上記の作業は自己責任でお願いします。