[wp-hackers] Need help with multiple orderby values

Rafael Ehlers rafaehlers at gmail.com
Wed Nov 16 01:49:13 UTC 2011


I have 3 posts (custom post type)

Post 0 -> ID = 0 -> meta_key = ca_type, meta_value = 1
Post 1 -> ID = 1 -> meta_key = ca_type, meta_value = 1
Post 2 -> ID = 2 -> meta_key = ca_type, meta_value = 0

The main query im using on (taxonomy.php) is:

$posts = query_posts(array(

get_query_var( 'taxonomy' ) => get_query_var( 'term' ),

'orderby' => 'meta_value_num ID',

'meta_key' => 'ca_type'

));

The actual result (and wrong one) is:

Post 0
Post 1
Post 2

However, Im expecting something like this (desired result):

Post 1
Post 0
Post 2

Since 'Post 1' have a greater ID than 'Post 0', and assuming that 'order'
=> 'DESC' is the default.

The basic idea, is to filter posts with meta_key ca_type = 1 first and then
between these 2 results, sort by ID (desc, greater, most recent first)

Any ideas what Im possible doing wrong here?!

Thanks in advance!

Rafael Ehlers


More information about the wp-hackers mailing list