order taxonomy alphabetical

时间:2017-01-31 作者:bigant841

我正在尽一切努力让我的自定义分类法按字母顺序显示,但似乎没有任何效果。我添加了orderby=标题和名称,但税务列表仍然显示其发布的顺序。这就是我要做的。该代码段用于显示基于所选税务的当前过帐信息。单击年份后,我在前端为一个职位(年份和类别)分配了两组税款,我要查看的职位将显示所有信息以及类别列表。类别列表是受控制的,也有税,但由于某种原因,我无法让此列表按字母顺序显示,而是根据发布日期发布。下面是我的代码

 function get_related_posts( $taxonomy = \'\', $args = array() ) {
if ( !is_single() )
    return false;
/* Check if we have a valid taxonomy*/
if ( !$taxonomy ) 
    return false;
$taxonomy = filter_var( $taxonomy, FILTER_SANITIZE_STRING );
if ( !taxonomy_exists( $taxonomy ) )
    return false;
$current_post = get_queried_object();

/* Get the post terms, just the ids*/
$terms = wp_get_post_terms( $current_post->ID, $taxonomy, array( \'fields\' => \'ids\') );
/* Lets only continue if we actually have post terms and if we don\'t have an WP_Error object. If not, return false*/
if ( !$terms || is_wp_error( $terms ) )
    return false;
/* Set the default query arguments*/
$defaults = array(
    \'post_type\' => $current_post->post_type,
    \'post__not_in\' => array( $current_post->ID),
    \'tax_query\' => array(
        array(
            \'taxonomy\' => $taxonomy,
            \'terms\' => $terms,
            \'include_children\' => false,
            \'orderby\' => \'title\',
        ),
    ),
);
/* Validate and merge the defaults with the user passed arguments*/
if ( is_array( $args ) ) {
    $args = wp_parse_args( $args, $defaults );
} else {
    $args = $defaults;
}

$q = get_posts( $args );

return $q;
 }
if ( function_exists( \'get_related_posts\' ) ) {
    $related_posts = get_related_posts( \'juryyear\', array( \'posts_per_page\' => 99,) );
    if ( $related_posts ) {
        foreach ( $related_posts as $post ) {
            setup_postdata( $post );
?>
            <li><a href="<?php echo get_permalink( $post->ID ); ?>"><?php $terms = get_the_terms( $post->ID , \'jury_category\' ); foreach ( $terms as $term ) { echo $term->name; }?></a></li>
<? } wp_reset_postdata(); } }?>
        </ul>
    </li>
</ul>

1 个回复
最合适的回答,由SO网友:bigant841 整理而成

我想出来了。我需要将“orderby”=>“menu\\u order”、“order”=>“ASC”添加到$related\\u posts=get\\u related\\u posts(\'juryyear\',数组(\'posts\\u per\\u page\'=>99,);