wp-custom-post-type-class
wp-custom-post-type-class copied to clipboard
Sorting Taxonomies
The query created when attempting sortable admin columns using automatic taxonomies doesn't work:
array (
'order' => 'asc',
'orderby' => 'meta_value',
'posts_per_page' => 200,
'post_type' => 'sm-item',
'meta_key' => 'sm-item-section',
)
Wasn't clear from the docs that only meta values were supported.
Might be a workable solution here: http://wordpress.stackexchange.com/questions/14306/using-wp-query-is-it-possible-to-orderby-taxonomy
Hey man... Attempted to replace 'orderby' => 'meta_value'
by 'orderby' => 'meta_value_num'
. @JacobDorman
The class is generating the wrong query, it should be more along the lines of:
array(
'order' => 'asc'
'orderby' => 'sm-item-section'
'post_type' => 'sm-item'
'posts_per_page' => 200
)
Where orderby
is the taxonomy name. I'll fix that in the class.
However, this wouldn't make taxonomies sortable on its own. To get it working you would need a post_clauses
filter too.
After reading of the stackoverflow and in particular this answer I'm skeptical about adding the posts_clauses
filter to the class.
Taxonomies aren't really meant to be sorted, they are used for grouping, not ordering. I can see that it might be possible and useful in some cases, but not all.
I'll need to look into it more.