Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我想在word press的选择框中获取当前类别术语_Php_Wordpress - Fatal编程技术网

Php 我想在word press的选择框中获取当前类别术语

Php 我想在word press的选择框中获取当前类别术语,php,wordpress,Php,Wordpress,这是我在word press中的分类码 <?php $terms = get_terms(['taxonomy' => 'listing_type', 'hide_empty' => false,]); if ($terms) { foreach ($terms as $term) { $selected = 'selected';

这是我在word press中的分类码

<?php
          $terms = get_terms(['taxonomy' => 'listing_type', 'hide_empty' => false,]);

                if ($terms) {
                foreach ($terms as $term) { 
                     $selected = 'selected';
                echo '<option value="' .  $term->name . '" '.$selected.' >' .esc_attr($term->name) . '</option>';
                }
                } ?>

您只需使用
wp\u下拉菜单\u categories()即可,而无需手动编写

这里的文档-

谢谢, 汤姆