サポート » プラグイン » カスタム投稿のタームを取得しフォームに入れる

  • 解決済 ANEMO-2

    (@anemo-2)


    カスタム投稿のタームを「function.php」にてショートコード作成し、

    CF7内で[shop_category_checkbox]で読み込んでいます。
    (まだ、グルメのカテゴリーしか作成していないので、他カテゴリーは空の状態です)

    表示はできたのですが、フォームのテスト送信行ったところ、
    複数選択して送信すると最後の一個のみしか届いてくれず、他はデフォルトのままなので、全くわからず困っております。

    どうぞ、よろしくお願いいたします。

    //フォーム内に動的にカスタム投稿タイプのターム一覧を表示
    function create_categorycheckbox(){
    
    $taxonomyName = 'shop_category';
    $args = array(
        'parent' => 0
    );
    //親を取得
    $terms = get_terms($taxonomyName,$args);
    foreach ($terms as $term) {
        //親のIDを取得
        $parentId = $term->term_id;
        $parentName = $term->name;
        $output .= "<h4 class='toggle'>$term->name" . "</h4><div class='toggle_txt'><span class='wpcf7-form-control wpcf7-checkbox'>";
        $childargs = array(
            'parent' => $parentId,
            'hide_empty'    => false
        ); 
        $childterms = get_terms( $taxonomyName , $childargs );
    
        foreach($childterms as $childterm){
        $output .= "<span class='wpcf7-list-item'><label><input type='checkbox' name='checkbox-shop_category' value='$childterm->name'><span class='wpcf7-list-item-label'> $childterm->name" . "</span></label></span>";
        }
    
        $output .= "</span></div>";
    }
    return $output;
    }
    wpcf7_add_form_tag('shop_category_checkbox', 'create_categorycheckbox', true);

    `

    • このトピックはANEMO-2が2年、 10ヶ月前に変更しました。
2件の返信を表示中 - 1 - 2件目 (全2件中)
  • こんにちは

    名前に角カッコが必要ではないでしょうか。
    name='checkbox-shop_category'

    name='checkbox-shop_category[]'

    • この返信は2年、 10ヶ月前にishitakaが編集しました。
    トピック投稿者 ANEMO-2

    (@anemo-2)

    早速のご回答、ありがとうございます。

    無事、取得できました、助かりました、ありがとうございます!!

2件の返信を表示中 - 1 - 2件目 (全2件中)
  • トピック「カスタム投稿のタームを取得しフォームに入れる」には新たに返信することはできません。