Smart Custom Fields で定義したカスタムフィールドのチェックボックスの「ラベル」を取得したいということなので・・・
SQLでデータベースを直接検索せずに WordPress の関数で書くならこんな感じでしょうか。
php
1$scf_posts = get_posts(array('post_type' => 'smart-custom-fields', 'post_title' =>'Smart Custom Fieldsのカスタムフィールドのタイトル'));
2foreach ($scf_posts as $scf_post) {
3 $scf_id = $scf_post->ID;
4}
5$scf_settings = get_post_meta($scf_id, 'smart-cf-setting', true);
6$scf_setting[] = maybe_unserialize($scf_settings[0]);
で、Smart Custom Fields の管理画面で設定した「カスタムフィールドのタイトル」の内容が、配列 $scf_setting に入ります。
$scf_setting['fields'] で、Smart Custom Fields で、設定した「フィールド」の内容が確認できます。
上記のスクリプトを実行すると $scf_setting['fields'][0]
に1番目のカスタムフィールドの内容が、$scf_setting['fields'][1]
に1番目のカスタムフィールドの内容が... と順に入ります。
例:
「カスタム1」というタイトルで、"チェックボックス1'"というフィールド名のチェックボックスを1つもつカスタムフィールドを作って、選択肢を「A, B, C, D」と定義したと仮定します。
上記のスクリプトの1行目を「カスタム1」にして実行してから、print_r($scf_setting['fields'][0]);
とすれば、
array (
'type' => 'check',
'name' => 'checkbox1',
'label' => 'チェックボックス1',
'choices' => 'A
B
C
D',
'check_direction' => 'horizontal',
'default' => '',
'instruction' => '',
'notes' => '',
)
と表示されます。
カスタムフィールドのチェックボックスの選択肢が必要なら $scf_setting['fields'][0]['choices']
で、選択肢が文字列で取り出せますので、文字列を分割してここの値に分けます。