At query level? Not possible.
{db_prefix}_postmeta
has only one field for value. WP serializes arrays before inserting them and deserializes after they’re out. So you have three choices here:
-
If you really need this sorting at query level (pagination, maybe?) you have to rethink your information architecture and start using a separate
custom_post_meta
field for each field that you want to sort by. -
Forget sorting.
-
If your number of items is limited and it’s going to remain limited, you could pull them all out with (
posts_per_page=-1
) and sort them witharray_multisort()
. As you might expect, this will slow the page down a bit (depending on the total number of posts that have that particularcustom_post_meta
).
As a variant to option 1, for performance reasons, depending on number of items and complexity of data, you might consider not using custom_post_meta
at all, but store it in a separate custom table.