実現したいこと
①Contact Form7のselectボックスにカスタム投稿タイプのタイトルを表示したい
②初期値を空白に設定したい
前提
①の部分は実装できましたが、
②の設定がうまくできません。
該当のソースコード
PHP
1<?php 2//Contact Form 7 のカスタマイズ 3function filter_wpcf7_form_tag( $scanned_tag, $replace ) { 4 5 if(!empty($scanned_tag)){ 6 7 //nameで判別 8 if($scanned_tag['name'] == 'recruit-select'){ 9 10 //カスタム投稿タイプの取得 11 global $post; 12 $args = array( 13 'posts_per_page' => -1, 14 'post_type' => 'recruit', 15 'order' => 'DESC', 16 ); 17 $customPosts = get_posts($args); 18 if($customPosts){ 19 foreach($customPosts as $post){ 20 setup_postdata( $post ); 21 22 $title = get_the_title(); 23 24 //$scanned_tagに情報を追加 25 $scanned_tag['values'][] = $title; 26 $scanned_tag['labels'][] = $title; 27 28 } 29 } 30 wp_reset_postdata(); 31 32 } 33 34 } 35 36 return $scanned_tag; 37}; 38 39add_filter( 'wpcf7_form_tag', 'filter_wpcf7_form_tag', 11, 2 ); 40?>
試したこと
ショートコードに「include_blank」を追記したり、
上記のコードを色々変更してみましたができませんでした。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。