Yes. Since the goal posts are out of bounds the ball is declared dead after striking an upright (or cross bar) at the point where it's no longer possible for it to pass thru them, or said differently, the ball is dead by rule after striking the upright when it then touches anything else that would prevent it from going thru the goal posts untouched.
Per 4.1.3.a: Ball Declared Dead
ARTICLE 3. A live ball becomes dead and an official shall sound his whistle or declare it dead:
a. When it goes out of bounds other than a kick that scores a field goal after touching the uprights or crossbar, when a ball carrier is out of bounds, or when a ball carrier is so held that his forward progress is stopped. When in question, the ball is dead (A.R. 4-2-1-II).