• Hi,

    I’ve created a custom post type called Player Manager, where I have all the players of a football team. The CPT has four different categories – goalkeepers, defenders, midfielders and strikers. I also gave it a few text fields, where the only important one, for now, is “number”.

    Here’s how I’ like it to show up in the archives page:

    Goalkeepers
    -1
    -21
    -24
    Defenders
    -3
    -4
    -5
    -11

    … So, what I want is for the posts to be ordered first by the categories and then by the numbers. I’ve managed to have them ordered by either categories or numbers (right now by numbers):

    ‘$querystr = “
    SELECT $wpdb->posts.*
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
    AND $wpdb->posts.post_type = ‘players’
    AND $wpdb->posts.post_status = ‘publish’
    AND $wpdb->postmeta.meta_key = ‘number’
    ORDER BY ABS ($wpdb->postmeta.meta_value) ASC
    “;
    $pageposts = $wpdb->get_results($querystr, OBJECT);’

    But that’s not how I’d like it. I guess I could do the same loop 4 times, but with different categories…but that feels quiet lame.

    Any help would be appreciated, thanks!

  • The topic ‘Order custom posts by taxonomy, then by meta_key’ is closed to new replies.