Skip to content

Instantly share code, notes, and snippets.

@DriftwoodJP
Last active January 3, 2016 20:39
Show Gist options
  • Save DriftwoodJP/8516751 to your computer and use it in GitHub Desktop.
Save DriftwoodJP/8516751 to your computer and use it in GitHub Desktop.
WordPress: shortcode が含まれたエントリをリストアップする | http://www.d-wood.com/blog/2014/01/21_5319.html
require 'mysql'
require 'inifile'
# 設定
mycnf = IniFile.load('/home/****/.my.cnf')['client']
sqls = {
default: "SELECT id FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND post_content LIKE '%[short-code%';"
}
# MySQL に接続情報を読み込む。
# .my.cnf が無ければ、下記に直接書く。
my = Mysql.new(mycnf['host'], mycnf['user'], mycnf['password'], mycnf['database'])
# 結果をリンクタグとして表示する。
sqls.each do |key, sql|
result = my.query(sql)
result.each do |row|
print '<a href="' , 'http://www.exsample.com/?p=', row[0], '"/>', row[0], '</a>', "\n"
end
end
my.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment