Everything in Its Right Place
A few days ago a member of the Genesis WordPress Facebook group asked about changing, removing and adding to the property details as used in the AgentPress Listings plugin in the AgentPress Pro Real Estate theme.
The theme adds 10 fields:
Remove and add
Removing ‘Square Feet:‘ and adding ‘Square Metres:‘ to the bottom of the ‘col2’ is easy.
Replace in place
Better is to replace ‘Square Feet:‘ with ‘Square Metres:‘ in the same place in the array. I found a solution for this from December 2015 on StackOverflow.
Inject an array
I decided to expand on this code to allow the injection of an array after a specific key in the original array.
The code goes through each key/value copying them to a new array. When it finds the search key, it appends the passed array to the new array. Then it continues to copy the original array’s contents to the new array.
And here is the result:
I browsed PHP’s various array functions but could not find any that inserted an array at a specific point. array_splice() looked promising but it does not preserve numeric keys. Furthermore, the keys in the replacement array are dropped and given numeric indices!