Php 我想在word press的选择框中获取当前类别术语
这是我在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';
<?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()即可,而无需手动编写
这里的文档-
谢谢,
汤姆