I derived the travel time in the question you linked:
\begin{align*} t&=\frac{v_y}{g}\left(1+\sqrt{1+\frac{2g(y+h)}{v_y^2}}\right) \\\ &=\sqrt{\frac{2\ell}{g}}\left(\xi+\sqrt{\xi^2+1+h/\ell-\cos\theta}\right) \end{align*}
where $\xi=\sin\theta\sqrt{\cos\theta-\cos\theta_m}$
and like before you now take $\frac{\mathrm{d}t}{\mathrm{d}\theta}=0$ and solve for $\theta$