OK, I think the problem with the relationship field choices was unrelated to my PHP code.
It seems if I don’t specify a title for a post the post’s relationship field choices don’t save. Not sure if this is a bug or intended behaviour but thought I’d mention it just in case!