I have created a custom taxonomy called 'attach_cats' for media attachments. Each term in the taxonomy has custom term metadata with a key of 'term_order' and meta value of an integer. I have added a custom column to the "edit-tag.php" page that displays the value of 'term_order'.
Now I would like to order the terms to 'orderby' the value of 'term_order'. I do this all the time on the "edit.php?post_type=page" with the following function:
add_action('pre_get_posts', 'sort_by_meta_key');
function sort_by_meta_key($query){
global $pagenow;
if(is_admin()
&& 'edit.php' == $pagenow
&& isset($_GET['post_type']) && $_GET['post_type']=='gallery'){
$query->set( 'meta_key', 'gallery_pos' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
}
}
But, when I try to do it with "terms" instead of "posts" using "pre_get_terms" it doesn't work. Here is what I have:
add_action('pre_get_terms', 'term_sort_order');
function term_sort_order($query){
global $pagenow;
if(is_admin()
&& 'edit-tags.php' == $pagenow
&& isset($_GET['post_type'] ) && $_GET['post_type']=='attachment' ){
$query->set( 'meta_key', 'term_order' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
}
}
// THIS RETURNS: Fatal error: Call to undefined method WP_Term_Query::set() ......
Any help would be greatly appreciated.