重新排序自定义 post 类别

Re-order custom post categories

我正在使用以下代码从自定义 post 类型中检索类别:

<?php 
     $taxonomy = 'treatment';
     $terms = get_terms($taxonomy);
     if ( $terms && !is_wp_error( $terms ) ) :
?>

     <ul>

<?php foreach ( $terms as $term ) { ?>

                <li>
                    <a href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
                        <h4><?php echo $term->name; ?></h4>
                    </a>
                </li>
<?php } ?>

        </ul>

<?php endif;?>

现在我希望能够对这些 post 进行重新排序,并且找到了一个合适的插件来执行此操作。但是,为了完成这项工作,我需要将 'orderby' => 'term_order' 添加到查询中。

这个循环甚至可能吗?我在上面尝试过这样的循环,但它不起作用。单独使用循环我无法获取自定义 post 类别:

<?php $loop = new WP_Query( array( 'post_type' => 'treatments', 'posts_per_page' => 1, 'orderby' => 'term_order' ) ); ?>

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    Content here

<?php endwhile; wp_reset_query(); ?>

将此给定代码放在 loop.And 中,请将 "custom_taxonomy_name" 替换为您为自定义 post 类型注册的自定义分类法名称

    <?php $terms = get_the_terms(get_the_ID(),'custom_taxonomy_name' ); ?>
            <?php foreach( $terms as $term): ?><br>
                <span class="text-category">Category:<?php echo $term->name; ?></span>
            <?php endforeach;  ?>