Skip to content

Instantly share code, notes, and snippets.

@yama
Last active January 27, 2017 12:13
Show Gist options
  • Save yama/aa97a5cb19c3a9060af51e55a545806e to your computer and use it in GitHub Desktop.
Save yama/aa97a5cb19c3a9060af51e55a545806e to your computer and use it in GitHub Desktop.
MODXでリソースID・ページタイトルなどと同時にテンプレート変数の値も取得する(1)
SELECT
DISTINCT
sc.id,
pagetitle,
(SELECT value FROM modx_site_tmplvar_contentvalues WHERE tmplvarid=3 AND contentid=sc.id LIMIT 1) AS 住所,
(SELECT value FROM modx_site_tmplvar_contentvalues WHERE tmplvarid=5 AND contentid=sc.id LIMIT 1) AS 電話番号
FROM modx_site_content sc
LEFT JOIN modx_site_tmplvar_contentvalues stc ON sc.id=stc.contentid
WHERE sc.parent=3
LIMIT 50
# サブクエリ2つなので多少重いはずだが、APIを使ってなんとかするよりはずっと軽い
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment