$post->post_type not working

Do you have global $post; above the if ('publish... statement?

Reference https://codex.wordpress.org/Function_Reference/$post