SQL: select custom field data in WordPress

ジャンプ先のURLを設定する項目(meta_keyが _url)を持つ有効なデータのみ取出す。
新しいものから10件取出す。
このSQLはWPの外で実行できる。

select cc.ID, cc.post_title, cc.meta_value, uu.name, cc.post_date from
(select aa.ID,aa.post_title,bb.meta_value,aa.post_date from tsl_posts aa,
( select post_id, meta_value from wp_postmeta where meta_key = ‘_url’ order by meta_value ) bb where aa.ID = bb.post_id and aa.post_status=’publish’ ) cc,
(select object_id, tt.name from wp_term_relationships, (select term_taxonomy_id, name from wp_term_taxonomy,wp_terms where wp_term_taxonomy.term_id = wp_terms.term_id) tt where wp_term_relationships.term_taxonomy_id = tt.term_taxonomy_id) uu where cc.ID=uu.object_id order by cc.post_date limit 10

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です