我正在处理插件并调用父类别和子类别。它看起来很完美,当我拖放父类别并保存订单时,它非常成功地保存在wp_term中的顺序,它在前面和管理面板上显示结果,当我拖放子类别并保存订单时,它也成功保存在wp_term中,它完美地显示了前面的结果,但在管理面板中它显示了我之前的订单。我不明白为什么
这是我的代码
<?php
$args = array(
'orderby' => 'term_order',
'order' => 'ASC',
'hide_empty' => false,
'parent' => $parent_ID,
);
$terms = get_terms( $tax, $args );
if ( $terms ) {
?>
<ul id="orderly-sortable" class="orderly-items">
<?php foreach ( $terms as $term ) : ?>
<li id="id_<?php echo $term->term_id; ?>" class="lineitem <?php echo ($i % 2 == 0 ? 'alternate ' : ''); ?>ui-state-default"><?php echo $term->name; ?>
<?php
$term_id = $term->term_id;
$child_terms = get_term_children( $term_id, $tax );
?>
<ul id="orderly-sortable" class="child-orderly-items">
<?php foreach ( $child_terms as $child_term ) : ?>
<?php $child = get_term_by( 'id', $child_term, $tax ); ?>
<li id="child_id_<?php echo $child->term_id; ?>" class="lineitem <?php echo ($c % 2 == 0 ? 'alternate ' : ''); ?>ui-state-default"><?php echo $child->name; ?></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
请帮帮我
我只想要保存在管理面板中的子类别订单......
答案 0 :(得分:0)
使用此
<?php
$args = array(
'orderby' => 'term_order',
'order' => 'ASC',
'hide_empty' => false,
'parent' => $parent_ID
);
$terms = get_terms( $tax, $args );
if ( $terms ) {
?>
<ul id="orderly-sortable" class="orderly-items">
<?php foreach ( $terms as $term ) : ?>
<li id="id_<?php echo $term->term_id; ?>" class="lineitem <?php echo ($i % 2 == 0 ? 'alternate ' : ''); ?>ui-state-default"><?php echo $term->name; ?>
<?php
$term_id = $term->term_id;
$args_child = array(
'orderby' => 'term_order',
'order' => 'ASC',
'hide_empty' => false,
'parent' => $term->term_id
);
$child_terms = get_terms($tax, $args_child);
?>
<ul id="orderly-sortable" class="child-orderly-items">
<?php foreach($child_terms as $child) : ?>
<li id="child_id_<?php echo $child->term_id; ?>" class="lineitem <?php echo ($c % 2 == 0 ? 'alternate ' : ''); ?>ui-state-default"><?php echo $child->name; ?></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
希望这对你有帮助