根据类别的下拉框选择自定义默认值

基本上,我想从生成的列表中自动选择一个类别,而不要在文本SELECT CATEGORY title="<?php esc_html_e('Category','service-finder'); ?>"中留空

该类别带有数字代码。

<div class="form-group has-select">
    <select class="sf-select-box form-control" name="signup_category" data-live-search="true" title="<?php esc_html_e('Category','service-finder'); ?>">
    </option>
    <?php
        if(class_exists('service_finder_texonomy_plugin')){
            $limit = 1000;
            $categories = service_finder_getcategoryList($limit);
            $texonomy = 'providers-category';
            if(!empty($categories)){
                foreach($categories as $category){
                $term_id = (!empty($category->term_id)) ? $category->term_id : '';
                $term_name = (!empty($category->name)) ? $category->name : '';
                echo '<option value="'.esc_attr($term_id).'" data-content="<span>'.esc_attr($term_name).'</span>">'. $term_name.'</option>';

                $term_children = get_term_children($term_id,$texonomy);
                if(!empty($term_children)){
                    $namearray = array();
                    foreach ($term_children as $child) {
                        $term = get_term_by( 'id',$child,$texonomy );
                        $namearray[$term->name]= $child;
                    }
                    ksort($namearray);

                    foreach($namearray as $term_child_id) {

                        $term_child = get_term_by('id',$term_child_id,$texonomy);

                        $term_child_id = (!empty($term_child_id)) ? $term_child_id : '';
                        $term_childname = (!empty($term_child->name)) ? $term_child->name : '';
                        echo '<option value="'.esc_attr($term_child_id).'" data-content="<span class=\'childcat\'>'.esc_attr($term_childname).'</span>">'. $term_childname.'</option>';

                    }
                }

                }
            }
        }
        ?>
    </select>
</div>

致谢

blackman1223 回答:根据类别的下拉框选择自定义默认值

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2892491.html

大家都在问