query_posts: need to filter by one meta key and sort by another
-
Hi folks,
I am trying to query posts, which have one meta key set to a specific value, and order them according to another meta key.
Obviously, one of these both things is easy to do.
To order the posts according to a meta key:
query_posts('meta_key=mykey1&orderby=meta_value');
and to filter the posts according to a meta key:
query_posts('meta_key=mykey2&meta_value=myvalue');
The problem is, I can’t define two different meta_keys in one wp_query.
I can whether set meta_key=mykey1 in order to sort by mykey1 or set met_key=mykey2 in order to filter by mykey2
Well, I know I could just do
if (get_meta("mykey2") != "myvalue") continue;
inside the loop, but this seems a little dirty to me, specially since, in my case, only very few posts will have the value “myvalue” assigned.
So, does anyone have any suggestions, on how to do this sort of thing?
- The topic ‘query_posts: need to filter by one meta key and sort by another’ is closed to new replies.