I have a custom post type and I want to be able to control the order that the posts are displayed by defining the order in an array, and then checking the posts meta_value against the array to see where it should sit in the order of posts.
Using the code below I can get the dealers who's 'Postcode' is one of the values defined in the $target_postcodes array of the 10 closest postcodes to the current users location.
$posts = get_posts(array(
'post_type' => 'dealer',
'meta_key' => 'Postcode',
'meta_value' => $target_postcodes,
'post_status' => 'publish'
));
Is it possible for me to sort the posts by the order of the values in the 'meta_values' query?
For example, if we use the following post values:
[Name] [Postcode]
Dealer 1 1234
Dealer 2 2345
Dealer 3 3456
Dealer 4 4567
And then the define the $target_postcodes array as
$target_postcodes = 4567,1234,3456,2345
I would then want the loop to display the dealers in the following order
Dealer 4
Dealer 1
Dealer 3
Dealer 2
Thanks, Brad