Check posts is an array before attempting to use array functions.