因此,我创建了一个自定义帖子类型,我们将其actors
称为,另一个名为movies
。因此,当我编辑电影时,我想要一个包含所有演员帖子的下拉列表,请选择一个并在前端输出该ID以与其他功能一起使用。这可行吗?我该怎么做
测试代码:
<?php
$data_terms = get_terms('test_post', array(
'orderby' => 'count',
'hide_empty' => 0,
'parent'=> 4 // You need the Id of the parent actors taxonomy
) );
?>
<select>
<?php foreach($data_terms as $term): ?>
<option>
<?php echo $term->name; echo $term->ID ?>
</option>
<?php endforeach ?>
</select>
作为PHP中的所有内容,要创建对象列表,您必须遵循以下步骤。
首先,获取数据。
<?php
$data_terms = get_terms('your_custom_taxonomy', array(
'orderby' => 'count',
'hide_empty' => 0,
'parent'=>13 // You need the Id of the parent actors taxonomy
) );
?>
现在,您可以根据需要显示它。您想要一个列表。所以:
<select>
<?php foreach($data_terms as $term): ?>
<option>
<?php echo $term->name; echo $term->ID ?>
</option>
<?php endforeach ?>
</select>
现在您有了ID。当然,您不想显示它,但是您可以将其传递到缓冲区中并随意使用。
希望他的帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句