[WordPress General] shortcode が含まれたエントリをリストアップする
条件に合うエントリを探します。
[markdown]
このスクリプトを流用して、まとめてみます。
> * [gems: ruby-mysql, inifile – .my.cnf の設定をロードして、Ruby から MySQL へ接続する | deadwood](https://www.d-wood.com/blog/2014/01/18_5295.html)
## インストール
gem をインストールします。
“`prettyprinted
% gem install ruby-mysql
% gem install inifile
“`
“`prettyprinted
% git clone https://gist.github.com/8516751.git
Cloning into ‘8516751’…
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity… done.
“`
## つかいかた
### ショートコードをみつける
使わなくなったプラグインのショートコードが含まれるエントリを探します。
探したいショートコードはこんな形式。
“`prettyprinted
[browser-shot url=”” width=”300″]
“`
“`sql
SELECT count(*) FROM wp_posts WHERE post_type = ‘post’ AND post_status = ‘publish’ AND post_content LIKE ‘%[browser-shot%’;
+———-+
| count(*) |
+———-+
| 6 |
+———-+
“`
上記エントリーの id をリストアップする。
“`prettyprinted
SELECT id FROM wp_posts WHERE post_type = ‘post’ AND post_status = ‘publish’ AND post_content LIKE ‘%[browser-shot%’;
“`
### 実行
“`prettyprinted
$ ruby wp_research.rb
“`
こんな形式のリンクを生成する。