Ordering custom taxonomy table
-
Hi,
Sorry if this is the wrong forum section if it is please let me know what the proper forum is to post this..
I have a custom taxonomy “my_taxonomy” and i store extra META information about each taxonomy in a custom DB table called “my_taxonomy_meta”.
Everything is working fine as far as adding, editing and deleting the Taxonomies as well as the META for each one. Also i’m able to add more columns to the taxonomy <table> (right side of “Add Taxonomy” form).
When it comes to sorting that table by the custom taxonomy meta within the DB table “my_taxonomy_meta” everything goes wrong. I tried using the below code and it just doesn’t want to work… I get a blank taxonomy <table>.
add_filter( “terms_clauses”, “my_taxonomy_columns_sort”, 10, 3 );
public static function my_taxonomy_columns_sort( $clauses, $taxonomy, $params ) {
global $wpdb;if ( $taxonomy[0] === “my_taxonomy” && isset( $_GET[‘orderby’] ) ) {
if( $_GET[‘orderby’] === “City” || $_GET[‘orderby’] === “State” ) {
switch( $_GET[“orderby”] ) {
case “City”:
$order_by = “addr_city”;
break;
case “State”:
$order_by = “addr_state”;
break;
default:
$order_by = “addr_state”;
break;
}$clauses[‘join’] .= ” LEFT JOIN
" . MY_TAXONOMY_META_TABLE_NAME . "
AS my_taxonomies_meta ON my_taxonomies_meta.id = t.term_id “;$clauses[‘orderby’] .= ” ORDER BY my_taxonomies_meta.{$order_by} {$params[‘order’]} “;
}
}return $clauses;
}Is it at all possible to order the table by the data that is pulled in from a non-standard WP DB table??
- The topic ‘Ordering custom taxonomy table’ is closed to new replies.