src/class-extended-cpt.php
public static function get_sort_taxonomy_clauses( array $clauses, array $vars, array $sortables ) : array {

		global $wpdb;

		if ( ! isset( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! is_string( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
			return [];
		}

		$orderby = $sortables[ $vars['orderby'] ];

		if ( ! is_array( $orderby ) ) {
			return [];
		}
		if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
			return [];
		}
		if ( ! isset( $orderby['taxonomy'] ) ) {
			return [];
		}

		# Taxonomy term ordering courtesy of http://scribu.net/wordpress/sortable-taxonomy-columns.html
		$clauses['join'] .= "
			LEFT OUTER JOIN {$wpdb->term_relationships} as ext_cpts_tr
			ON ( {$wpdb->posts}.ID = ext_cpts_tr.object_id )
			LEFT OUTER JOIN {$wpdb->term_taxonomy} as ext_cpts_tt
			ON ( ext_cpts_tr.term_taxonomy_id = ext_cpts_tt.term_taxonomy_id )
			LEFT OUTER JOIN {$wpdb->terms} as ext_cpts_t
			ON ( ext_cpts_tt.term_id = ext_cpts_t.term_id )
		";
		$clauses['where'] .= $wpdb->prepare( ' AND ( taxonomy = %s OR taxonomy IS NULL )', $orderby['taxonomy'] );
		$clauses['groupby'] = 'ext_cpts_tr.object_id';
		$clauses['orderby'] = 'GROUP_CONCAT( ext_cpts_t.name ORDER BY name ASC ) ';
		$clauses['orderby'] .= ( isset( $vars['order'] ) && ( 'ASC' === strtoupper( $vars['order'] ) ) ) ? 'ASC' : 'DESC';

		return $clauses;

	}
public static function get_sort_taxonomy_clauses( array $clauses, array $vars, array $sortables ) : array {

		global $wpdb;

		if ( ! isset( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! is_string( $vars['orderby'] ) ) {
			return [];
		}
		if ( ! isset( $sortables[ $vars['orderby'] ] ) ) {
			return [];
		}

		$orderby = $sortables[ $vars['orderby'] ];

		if ( ! is_array( $orderby ) ) {
			return [];
		}
		if ( isset( $orderby['sortable'] ) && ! $orderby['sortable'] ) {
			return [];
		}
		if ( ! isset( $orderby['taxonomy'] ) ) {
			return [];
		}

		# Taxonomy term ordering courtesy of http://scribu.net/wordpress/sortable-taxonomy-columns.html
		$clauses['join'] .= "
			LEFT OUTER JOIN {$wpdb->term_relationships} as ext_cpts_tr
			ON ( {$wpdb->posts}.ID = ext_cpts_tr.object_id )
			LEFT OUTER JOIN {$wpdb->term_taxonomy} as ext_cpts_tt
			ON ( ext_cpts_tr.term_taxonomy_id = ext_cpts_tt.term_taxonomy_id )
			LEFT OUTER JOIN {$wpdb->terms} as ext_cpts_t
			ON ( ext_cpts_tt.term_id = ext_cpts_t.term_id )
		";
		$clauses['where'] .= $wpdb->prepare( ' AND ( taxonomy = %s OR taxonomy IS NULL )', $orderby['taxonomy'] );
		$clauses['groupby'] = 'ext_cpts_tr.object_id';
		$clauses['orderby'] = 'GROUP_CONCAT( ext_cpts_t.name ORDER BY name ASC ) ';
		$clauses['orderby'] .= ( isset( $vars['order'] ) && ( 'ASC' === strtoupper( $vars['order'] ) ) ) ? 'ASC' : 'DESC';

		return $clauses;

	}
public static function get_sort_taxonomy_clauses ( array $ clauses , array $ vars , array $ sortables ) : array { global $ wpdb ; if ( ! isset ( $ vars [ 'orderby' ] ) ) { return [ ] ; } if ( ! is_string ( $ vars [ 'orderby' ] ) ) { return [ ] ; } if ( ! isset ( $ sortables [ $ vars [ 'orderby' ] ] ) ) { return [ ] ; } $ orderby = $ sortables [ $ vars [ 'orderby' ] ] ; if ( ! is_array ( $ orderby ) ) { return [ ] ; } if ( isset ( $ orderby [ 'sortable' ] ) && ! $ orderby [ 'sortable' ] ) { return [ ] ; } if ( ! isset ( $ orderby [ 'taxonomy' ] ) ) { return [ ] ; } # Taxonomy term ordering courtesy of http://scribu.net/wordpress/sortable-taxonomy-columns.html $ clauses [ 'join' ] .= "
			LEFT OUTER JOIN {$wpdb->term_relationships} as ext_cpts_tr
			ON ( {$wpdb->posts}.ID = ext_cpts_tr.object_id )
			LEFT OUTER JOIN {$wpdb->term_taxonomy} as ext_cpts_tt
			ON ( ext_cpts_tr.term_taxonomy_id = ext_cpts_tt.term_taxonomy_id )
			LEFT OUTER JOIN {$wpdb->terms} as ext_cpts_t
			ON ( ext_cpts_tt.term_id = ext_cpts_t.term_id )
		" ; $ clauses [ 'where' ] .= $ wpdb -> prepare ( ' AND ( taxonomy = %s OR taxonomy IS NULL )' , $ orderby [ 'taxonomy' ] ) ; $ clauses [ 'groupby' ] = 'ext_cpts_tr.object_id' ; $ clauses [ 'orderby' ] = 'GROUP_CONCAT( ext_cpts_t.name ORDER BY name ASC ) ' ; $ clauses [ 'orderby' ] .= ( isset ( $ vars [ 'order' ] ) && ( 'ASC' === strtoupper ( $ vars [ 'order' ] ) ) ) ? 'ASC' : 'DESC' ; return $ clauses ; }
Get the array of SQL clauses for the given sortables, to apply to the current query in order to
sort it by the requested orderby field.

@param  array $clauses   The query's SQL clauses.
@param  array $vars      The public query vars, usually from `$wp_query->query`.
@param  array $sortables The sortables valid for this query (usually the value of the `admin_cols` or
`site_sortables` argument when registering an extended post type).
@return array            The list of SQL clauses to apply to the query.
Get the array of SQL clauses for the given sortables to apply to the current query in order to sort it by the requested orderby field .