Wordpress: Sort posts by meta value after AFTER querying from database

Posted by Joseph Carrington on Stack Overflow See other posts from Stack Overflow or by Joseph Carrington
Published on 2010-05-23T19:13:31Z Indexed on 2010/05/23 19:21 UTC
Read the original article Hit count: 288

Hello, I am pulling posts from my database by using Wordpress' WP_Query object like so:

$shows_query = new WP_Query("category_name=shows&meta_key=band&meta_value=$artist_id");

I have another meta value I would like to sort the posts by, however. The meta key is 'date'.

The WP_Query object can no work with multiple meta_keys, so this does not work:

$shows_query = new WP_Query("category_name=shows&meta_key=band&meta_value=$artist_id&meta_key=date&orderby=meta_value&order=DESC");

So now I have to figure out a way to sort the posts in $shows_query['posts'] by one of their meta_values, which are not even IN their array. Any other, more sensible approach would also be appreciated.

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about multidimensional-array