LoginSignup
0
0

More than 5 years have passed since last update.

worpdressのデータをcustom post と合わせてselectする

Posted at

wordpressのカスタムポストと合わせてセレクト

LEFT JOIN をつなげて使うことで出力できる。


SELECT p.ID, p.post_name, p.post_title,
custom_post_01.meta_value AS custom_post_01,
custom_post_02.meta_value AS custom_post_02,
custom_post_03.meta_value AS custom_post_03
FROM wp_posts AS p
LEFT JOIN wp_postmeta AS custom_post_01 ON p.ID = custom_post_01.post_id AND 'custom_post_01' = custom_post_01.meta_key
LEFT JOIN wp_postmeta AS custom_post_02 ON p.ID = custom_post_02.post_id AND 'custom_post_02' = custom_post_02.meta_key
LEFT JOIN wp_postmeta AS custom_post_03 ON p.ID = custom_post_03.post_id AND 'custom_post_03' = custom_post_03.meta_key

参考:
http://stackoverflow.com/questions/26319613/improving-a-query-using-a-lot-of-inner-joins-to-wp-postmeta-a-key-value-table

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0