title: Wordpress: pre_get_posts and order by taxonomy term
body: <p>I have a category archive with a custom taxonomy "client". Now I want to order the category archive by the term of the custom taxonomy (the client name). I tried to query it by meta_value and a advanced custom taxonomy query, but I could not get it to be ordered by the name of the taxonomy term. Any suggestions to get a Wordpress loop ordered by taxonomy term name? See line $query->set( 'orderby', 'how_to_order_by_taxonomy_name' );</p>
  
  <p><strong>Registering the taxonomy</strong></p>
  
  <pre><code>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' =&gt; false,
              'public' =&gt; true,
              'query_var' =&gt; true,
              'rewrite' =&gt; true,
              'labels' =&gt; array(
                  'name'                =&gt; _x( 'Clients', 'taxonomy general name' ),
                  'singular_name'       =&gt; _x( 'Client', 'taxonomy singular name' ),
                  'search_items'        =&gt; __( 'Search Clients' ),
                  'all_items'           =&gt; __( 'All Clients' ),
                  'edit_item'           =&gt; __( 'Edit Client' ), 
                  'update_item'         =&gt; __( 'Update Client' ),
                  'add_new_item'        =&gt; __( 'Add New Client' ),
                  'new_item_name'       =&gt; __( 'New Client Name' ),
                  'menu_name'           =&gt; __( 'Client' )
              ),
          )
      );
  }
  </code></pre>
  
  <p><strong>pre_get_posts Query</strong></p>
  
  <pre><code>add_action( 'pre_get_posts', 'jp_project_taxonomy_queries' );
  
  function jp_project_taxonomy_queries( $query ) {
  
      if(!is_admin() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; 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' =&gt; $tax_order)) as $tax ) {
                  $taxonomies[] = $tax-&gt;name;
              }
  
              $taxquery = array(
                  array(
                      'taxonomy' =&gt; 'client',
                      'terms' =&gt; $taxonomies,
                      'field' =&gt; 'slug',
                  )
              );
  
              $query-&gt;set( 'tax_query', $taxquery );
              $query-&gt;set( 'orderby', 'how_to_order_by_taxonomy_name' );
  
          endif;
  
      endif;
  
  }
  </code></pre>