Search Regexをカスタム投稿タイプに対応させる方法


関連記事はこちら Search Regex でカスタムフィールドの検索のバグを修正

 

文字列置換プラグイン、Search Regex

 

便利だけど、カスタム投稿タイプに対応していない。

 

というわけで、カスタマイズ、カスタマイズ。

 

修正ファイルは post_content.php

plugins/search-regex/searches/post_content.php

がっつりプラグインのコアファイルをいじります。
(アップデートで上書きされるが怖い)

 

やり方は2つあるので、お好きなほうをどうぞ。

 

■ 変更

$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" );

 

■ 変更(やり方:その1)

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

カスタム投稿「news」を追加した。

 

■ 変更(やり方:その2)

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

AND post_type IN (‘post’,’page’)」 を削除した。