AdvancedCustomFields/acf5-beta — pull request #275 by jarednova (2014-06-11 14:48:46+00:00)
Title: Fixed ordering of order_by_search to preserve keys

The relationship field currently doesn't work when you add posts that are returned from a search. The `acf_order_by_search` function has some logic to help weight results based on where the search term appears in the title (so if I search for "pumpkin" the post "Pumpkins are a good food" will appear before "A good decoration for Halloween is pumpkins")

This is because the sort going on in `acf_order_by_search` kills the keys (which is how the post id info is stored). Thus when adding to your selected posts in relationships it thinks the post id is 0, 1 or 2 (etc.) based on its order in the array.

This PR changes the sort algorithm to preserve those keys and thus properly save the posts selected into the resulting relationship.