WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to sort posts by custom taxonomy (shoe_color) ASC|DESC? I would like to do this using query_posts and passing the orderby=shoe_color into it.

Here is the code I'm trying to work out:

function shoe_color_orderby( $wp_query ) {
    global $wpdb;
    return "(
        FROM $wpdb->term_relationships
        INNER JOIN $wpdb->term_taxonomy USING (term_taxonomy_id)
        INNER JOIN $wpdb->terms USING (term_id)
        WHERE $wpdb->posts.ID = object_id
        AND taxonomy = 'shoe_color'
        GROUP BY object_id
    ) ";
add_filter( 'posts_orderby', 'shoe_color_orderby');
share|improve this question
Check this search queries: posts_orderby and pre_get_posts – brasofilo Jul 10 '13 at 23:21
I guess this is what you are looking for: wordpress.stackexchange.com/questions/14306/… – rfrq Jul 11 '13 at 14:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.