public function makeAdminTaxonomyColumnsSortable($clauses, $wp_query)
    {
        global $wpdb;
        
        // Not sorting at all? Get out.
        if (!array_key_exists('orderby', $wp_query->query)) {
            return $clauses;
        }
        if ($wp_query->query['orderby'] !== 'meta_value') {
            return $clauses;
        }
        if (!array_key_exists('meta_key', $wp_query->query)) {
            return $clauses;
        }

        // No taxonomies defined? Get out.
        $taxonomies = $this->getTaxonomies();
        if (!Arr::iterable($taxonomies)) {
            return $clauses;
        }

        // Not sorting by a taxonomy? Get out.
        $sortable_taxonomy_key = null;
        foreach ($taxonomies as $taxonomy_key => $taxonomy) {
            $taxonomy_key = (is_int($taxonomy_key)) ? $taxonomy : $taxonomy_key;
            if ($wp_query->query['meta_key'] !== $taxonomy_key) {
                continue;
            }

            $sortable_taxonomy_key = $taxonomy_key;
            break;
        }
        if (!$sortable_taxonomy_key) {
            return $clauses;
        }
        if ($wp_query->query['meta_key'] !== $sortable_taxonomy_key) {
            return $clauses;
        }
        
        // Now we know which taxonomy the user is sorting by
        // but WordPress will think we're sorting by a meta_key.
        // Correct for this bad assumption by WordPress.
        $clauses['where'] = str_replace(
            array(
                "AND ({$wpdb->postmeta}.meta_key = '".$taxonomy."' )",
                "AND ( \n  {$wpdb->postmeta}.meta_key = '".$taxonomy."'\n)"
            ),
            '',
            $clauses['where']
        );
        
        // This is how we find the posts
        $clauses['join'] .= "
            LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
            LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
            LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
        ";
        $clauses['where'] .= "AND (taxonomy = '".$taxonomy."' OR taxonomy IS NULL)";
        $clauses['groupby'] = "object_id";
        $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)";
        $clauses['orderby'] .= (strtoupper($wp_query->get('order')) == 'ASC') ? 'ASC' : 'DESC';
        return $clauses;
    }
public function makeAdminTaxonomyColumnsSortable($clauses, $wp_query)
    {
        global $wpdb;
        
        // Not sorting at all? Get out.
        if (!array_key_exists('orderby', $wp_query->query)) {
            return $clauses;
        }
        if ($wp_query->query['orderby'] !== 'meta_value') {
            return $clauses;
        }
        if (!array_key_exists('meta_key', $wp_query->query)) {
            return $clauses;
        }

        // No taxonomies defined? Get out.
        $taxonomies = $this->getTaxonomies();
        if (!Arr::iterable($taxonomies)) {
            return $clauses;
        }

        // Not sorting by a taxonomy? Get out.
        $sortable_taxonomy_key = null;
        foreach ($taxonomies as $taxonomy_key => $taxonomy) {
            $taxonomy_key = (is_int($taxonomy_key)) ? $taxonomy : $taxonomy_key;
            if ($wp_query->query['meta_key'] !== $taxonomy_key) {
                continue;
            }

            $sortable_taxonomy_key = $taxonomy_key;
            break;
        }
        if (!$sortable_taxonomy_key) {
            return $clauses;
        }
        if ($wp_query->query['meta_key'] !== $sortable_taxonomy_key) {
            return $clauses;
        }
        
        // Now we know which taxonomy the user is sorting by
        // but WordPress will think we're sorting by a meta_key.
        // Correct for this bad assumption by WordPress.
        $clauses['where'] = str_replace(
            array(
                "AND ({$wpdb->postmeta}.meta_key = '".$taxonomy."' )",
                "AND ( \n  {$wpdb->postmeta}.meta_key = '".$taxonomy."'\n)"
            ),
            '',
            $clauses['where']
        );
        
        // This is how we find the posts
        $clauses['join'] .= "
            LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
            LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
            LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
        ";
        $clauses['where'] .= "AND (taxonomy = '".$taxonomy."' OR taxonomy IS NULL)";
        $clauses['groupby'] = "object_id";
        $clauses['orderby'] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)";
        $clauses['orderby'] .= (strtoupper($wp_query->get('order')) == 'ASC') ? 'ASC' : 'DESC';
        return $clauses;
    }
public function makeAdminTaxonomyColumnsSortable ( $ clauses , $ wp_query ) { global $ wpdb ; // Not sorting at all? Get out. if ( ! array_key_exists ( 'orderby' , $ wp_query -> query ) ) { return $ clauses ; } if ( $ wp_query -> query [ 'orderby' ] !== 'meta_value' ) { return $ clauses ; } if ( ! array_key_exists ( 'meta_key' , $ wp_query -> query ) ) { return $ clauses ; } // No taxonomies defined? Get out. $ taxonomies = $ this -> getTaxonomies ( ) ; if ( ! Arr :: iterable ( $ taxonomies ) ) { return $ clauses ; } // Not sorting by a taxonomy? Get out. $ sortable_taxonomy_key = null ; foreach ( $ taxonomies as $ taxonomy_key => $ taxonomy ) { $ taxonomy_key = ( is_int ( $ taxonomy_key ) ) ? $ taxonomy : $ taxonomy_key ; if ( $ wp_query -> query [ 'meta_key' ] !== $ taxonomy_key ) { continue ; } $ sortable_taxonomy_key = $ taxonomy_key ; break ; } if ( ! $ sortable_taxonomy_key ) { return $ clauses ; } if ( $ wp_query -> query [ 'meta_key' ] !== $ sortable_taxonomy_key ) { return $ clauses ; } // Now we know which taxonomy the user is sorting by // but WordPress will think we're sorting by a meta_key. // Correct for this bad assumption by WordPress. $ clauses [ 'where' ] = str_replace ( array ( "AND ({$wpdb->postmeta}.meta_key = '" . $ taxonomy . "' )" , "AND ( \n  {$wpdb->postmeta}.meta_key = '" . $ taxonomy . "'\n)" ) , '' , $ clauses [ 'where' ] ) ; // This is how we find the posts $ clauses [ 'join' ] .= "
            LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
            LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
            LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
        " ; $ clauses [ 'where' ] .= "AND (taxonomy = '" . $ taxonomy . "' OR taxonomy IS NULL)" ; $ clauses [ 'groupby' ] = "object_id" ; $ clauses [ 'orderby' ] = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)" ; $ clauses [ 'orderby' ] .= ( strtoupper ( $ wp_query -> get ( 'order' ) ) == 'ASC' ) ? 'ASC' : 'DESC' ; return $ clauses ; }
Make the admin taxonomy columns sortable
Admittedly this is a bit hackish
@link http://wordpress.stackexchange.com/questions/109955/custom-table-column-sortable-by-taxonomy-query
@param array $clauses
@param object $wp_query
@return array
Make the admin taxonomy columns sortable Admittedly this is a bit hackish