The SQL query triggered by get_post_custom()
is in update_meta_cache()
and it looks like this:
$wpdb->get_results(
$wpdb->prepare(
"SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
$meta_type
),
ARRAY_A
);
So there is no ORDER BY
given.
Without ORDER BY
the resulting order is almost unpredictable: it depends on the optimizer, used indexes and their order.
The order the fields are saved doesn’t matter here.
You can filter 'query'
and add an ORDER BY
clause to the query. See wp-includes/wp-db.php
– wpdb::query()
for details.