I haven't dug in here really (hence the initial punt) - but would this ever produce an "Attempting to access property on non-object" notice if $post wasn't an object?