我有一个带有自定义分类“客户”的类别存档 . 现在,我想按自定义分类(客户名称)的术语订购类别归档 . 我尝试通过meta_value和高级自定义分类查询来查询它,但我无法通过分类术语的名称对其进行排序 . 有任何建议来获得按分类学术语名称排序的Wordpress循环吗?见行$ query-> set('orderby','how_to_order_by_taxonomy_name');

Registering the taxonomy

add_action( 'init', 'jp_register_project_taxonomies', 0 );
function jp_register_project_taxonomies() {

    // register taxonomy to hold our clients
    register_taxonomy(
        'client',
        array( 'post' ),
        array(
            'hierarchical' => false,
            'public' => true,
            'query_var' => true,
            'rewrite' => true,
            'labels' => array(
                'name'                => _x( 'Clients', 'taxonomy general name' ),
                'singular_name'       => _x( 'Client', 'taxonomy singular name' ),
                'search_items'        => __( 'Search Clients' ),
                'all_items'           => __( 'All Clients' ),
                'edit_item'           => __( 'Edit Client' ), 
                'update_item'         => __( 'Update Client' ),
                'add_new_item'        => __( 'Add New Client' ),
                'new_item_name'       => __( 'New Client Name' ),
                'menu_name'           => __( 'Client' )
            ),
        )
    );
}

pre_get_posts Query

add_action( 'pre_get_posts', 'jp_project_taxonomy_queries' );

function jp_project_taxonomy_queries( $query ) {

    if(!is_admin() && $query->is_main_query() && is_category() ):

        if (get_query_var('poby') == 'client'):

            $taxonomies = array();
            $tax_order = (get_query_var('po') == 'DESC' ?  'DESC' : 'ASC' );

            foreach (get_terms('client', array('order' => $tax_order)) as $tax ) {
                $taxonomies[] = $tax->name;
            }

            $taxquery = array(
                array(
                    'taxonomy' => 'client',
                    'terms' => $taxonomies,
                    'field' => 'slug',
                )
            );

            $query->set( 'tax_query', $taxquery );
            $query->set( 'orderby', 'how_to_order_by_taxonomy_name' );

        endif;

    endif;

}