Call child categories with term_order issue

833 views Asked by At

I am working on a plugin and call parent categories and child categories. It appears perfectly, and when i drag and drop parent category and save the order, it save order in wp_term very successfully and it shows me result on front and admin panel, and when i drag and drop child category and save the order, it also save in wp_term successfully and it shows me result on front perfectly but in admin panel it shows me previous order. i don't get why

here is my code

<?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>

Please help me

I only want child category order which i saved in admin panel......

1

There are 1 answers

0
deemi-D-nadeem On BEST ANSWER

use this

<?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>

Hope this is help you