I am using advanced custom fields wordpress plugin and a custom post type called "albums".
In the custom post type I have 2 custom fields.
One is a "user"-type-field called "album_artists" which stores an array with user ids into the database.
The other one is a field called "release_date" which stores a timestamp into the database and is a required field.
Now, in authors.php I get all "album"-posts that contain the current author's id in the "album_artists" field. So far so good. I managed this with a custom query which looks for \"{userID}\" in the serialized array of the "album_artists"-field and I am able to get the posts that I want. But now I want to order the albums-posts (which are currently ordered by post date) by the other custom field's ("release_date") value with the timestamp in it.
Is it possible with a single SQL query or is there any other idea to achieve this? Here's my custom query:
global $wpdb;
$results = $wpdb->get_results("
SELECT * FROM $wpdb->posts WHERE `ID` IN (
SELECT `post_id`
FROM $wpdb->postmeta
WHERE `meta_key` LIKE 'album_artists'
AND `meta_value` LIKE '%\"{$curauth->ID}\"%'
)
AND `post_type` LIKE 'albums'
AND `post_status` LIKE 'publish'
ORDER BY 'post_date' ASC
", OBJECT);