How to load another post if condition is true

You can provide the desired post ID to get_post. So inside your conditional, do the work to determine the post ID you need ($new_post_id), then use $post = get_post( $new_post_id ).

error code: 523