Added a check to make sure post object is set before trying to access it