[wp-hackers] Need help with multiple orderby values

Otto otto at ottodestruct.com
Wed Nov 16 02:17:06 UTC 2011


Not sure on the reason why you're getting odd results, but this bit is wrong:

$posts = query_posts(...)

query_posts doesn't return anything useful, as it simply modifies the
main query. Also, $posts is a global variable, so you might be
interfering with it somehow that way.

-Otto



On Tue, Nov 15, 2011 at 7:49 PM, Rafael Ehlers <rafaehlers at gmail.com> wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list